-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4-1.py
More file actions
33 lines (27 loc) · 785 Bytes
/
Copy path4-1.py
File metadata and controls
33 lines (27 loc) · 785 Bytes
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
import pickle
bfilename = 'd:/bbb/test.bin'
tfilename = 'd:/bbb/test.txt'
data1 = 77
data2 = "Hello, World!"
data3 = ["car","apple","house"]
with open(bfilename, "wb") as f:
pickle.dump(data1,f)
pickle.dump(data2,f)
pickle.dump(data3,f)
with open(tfilename, "wt") as f:
f.write(str(data1))
f.write('\n')
f.write(data2)
f.write('\n')
f.writelines('\n'.join(data3))
f.write('\n')
with open(bfilename, 'rb') as f:
b = pickle.load(f)
print(type(b), ' Binary Read1 | ', b)
b = pickle.load(f)
print(type(b), ' Binary Read2 | ', b)
b = pickle.load(f)
print(type(b), ' Binary Read3 | ', b)
with open(tfilename, 'rt') as f:
for i, line in enumerate(f, 1):
print(type(line), 'Text Read' + str(i) + '|', line, end='')