Repository navigation
Expand file tree
/
Copy pathfiles.py
More file actions
83 lines (54 loc) · 1.72 KB
/
Copy pathfiles.py
File metadata and controls
83 lines (54 loc) · 1.72 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
try:
with open('text.txt') as fobj:
contents = fobj.read()
print(contents)
except Exception as e:
print("File Error ", e)
______________
with open('text.txt') as fobj:
for number, lines in enumerate(fobj):
print (number+1, lines.upper())
______________
with open('number.txt', 'w'/'a') as fobj:
fobj.write('100')
fobj.write('\n')
fobj.write('5000')
fobj.write('\n')
fobj.write('10000')
_______________
with open('number.txt', 'a', encoding='utf-8') as fobj:
fobj.write('use utf-8 for bangla text')
fobj.write('\n')
fobj.write('use utf-8 for bangla text')
_______________
with open('nothing.txt', 'a', encoding='utf-8') as fobj:
print("Nothing goes unpaid", file=fobj)
_______________ binary-files write and read____________
with open('binary', 'wb') as fobj:
fobj.write(b'Life is extreamly bad')
with open('binary', 'rb') as fobj:
binary_data = fobj.read()
decode_data = binary_data.decode('utf-8')
print(decode_data)
__________________________
import os
if os.path.exists('nothing.txt'):
print('Yes! your files exist !!!!')
else:
print('File does not exists')
_______________________
from tempfile import TemporaryFile
with TemporaryFile('w+') as fobj:
fobj.write("Life is cool . \n")
fobj.seek(0)
data = fobj.read()
print(data)
____________________serialize________
import pickle
dict_data = {'name':'Ahsan', 'country':'bangladesh'}
with open('serialize', 'wb') as fobj:
pickle.dump(dict_data, fobj)
with open('serialize', 'rb') as fobj:
dict_data= pickle.load(fobj)
print(dict_data)
________________________