-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile.py
43 lines (37 loc) · 1.31 KB
/
file.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
print('File operations')
# f = open('file.txt')
# print('Is file open:',f)
# newf = open('hello.txt', mode='a')
# print('Create new file hello.txt:',newf)
# f.close()
# newf.close()
# use safe mode avop mode is not safe on so use tye filan
try:
f = open('file.txt')
# best way to use the is - with
with open('file.txt',mode='w') as f:
f.write('kya baat hai maza hi aa gaya. mast hai python hain na\n')
f.write('ye jo bate hai ye to hoti hi rangei\n\n')
f.write('magar agar kaha jaye to maja aata hai python me aur hai hi majedat')
# f.write('this is my first file\n')
# f.write('no problem to wirht here\n')
# f.write('it\'s great idea to writh in the file by python.\n\n')
# f.write('really awesome')
# with open('file.txt','r') as f:
# print(f)
# newf = open('hello.txt',mode='a')
# print('created file:',f)
# print('Create new file using a:',newf)
finally:
f.close()
# newf.close()
# read('file.txt')
readfile = open('file.txt','r')
print(open('file.txt', 'r').read())
print('current file position:',readfile.tell())
print('bright currsor to initial posion',readfile.seek(0))
# read file in loop
print('\n\n')
for i in readfile:
print(i,end='') #end use to stope reapeting double new line
print(readfile.readline())