-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path22_file_handling.py
44 lines (37 loc) · 1.21 KB
/
22_file_handling.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File Handling
# File: Create | Read | Update/Modify | Delete
# Inside File : Modes
# if file aleray exists: read (r)
# if file not exists: append (a)
# if write a file: write (w)
# if file not exits use w because w creates new file
# else use x to open file in write mode because it will reamin previous data as on
# if write a file but not exists: create (x)
# use open() method to open file in read or write mode
# open file
# bioData = open('daksh_a.txt', 'a')
# print('\nCheck newly create file output: ', bioData)
# Create new file and enter few data
# bioData = 'Hello Daksh how are you?'
# bioData = input('\nEntery your bio data? \n')
# bioData = {
# 'Name': 'Daksh',
# 'Course': 'Python',
# }
bioData = '''Name: Daksh
Course: Python'''
# Check with w to override exising data
# openFile = open('daksh.txt', 'w')
# CHeck with x to append new data on fiel
openFile = open('daksh_2.txt','a')
# openFile.write('Hello Daksh how are you?')
openFile.write(bioData)
# close this file
openFile.close()
# open fiel again in read mode
readBioData = open('daksh.txt','r')
# readBioData.writ
# readBioData.write(bioData)
getData = readBioData.read()
print('\n', getData, '\n')
readBioData.close()