-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiles.py
More file actions
50 lines (34 loc) · 1.22 KB
/
files.py
File metadata and controls
50 lines (34 loc) · 1.22 KB
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
45
46
"""
r = read
w = write (overwrite)
a = append (append on existing)
r+ = read and write(append)
"""
# fileObject = open('workfile.txt', 'r')
# # readData = fileObject.read()
# readData = fileObject.readline()
# fileObject.close()
# print(fileObject.closed)
# #This operation will read your existing file
# with open('workfile.txt', 'r') as fileObject:
# readData = fileObject.read()
# print(readData)
# #This operation will overwrite your existing file
# with open('workfile.txt', 'w') as fileObject:
# readData = fileObject.write('My name is Akash)
# print(readData)
# #This operation will append data to your existing file
# with open('workfile.txt', 'a') as fileObject:
# readData = fileObject.write('My name is Akash)
# print(readData)
# with open('workfile.txt', 'w') as fileObject:
# readData = fileObject.write('abcdefg')
with open('workfile.txt', 'r+') as fileObject:
readData = fileObject.read()
print(readData)
fileObject.truncate(0) # this will truncate your data from 0 offsets
fileObject.write('Hello My name is salahuddin')
# readData = fileObject.truncate(0)
with open('workfile.txt', 'r+') as fileObject:
readData = fileObject.read()
print(readData)