-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadWriteFile.py
More file actions
37 lines (30 loc) · 787 Bytes
/
readWriteFile.py
File metadata and controls
37 lines (30 loc) · 787 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
34
35
36
37
# will overwrite
"""
# Copy file
with open('test.txt', 'r') as rf:
with open('test_copy.txt', 'w') as wf:
for line in rf:
wf.write(line)
"""
crop = 0
with open('keyart1_fade.jpg', 'rb') as rf:
with open('test_copy.jpg', 'wb') as wf:
for line in rf:
crop = crop +1
# write file to wf but stop after crop specified
if crop < 256:
wf.write(line)
# Copy Picture in chunks
"""
with open('keyart1_fade.jpg', 'rb') as rf:
with open('test_copy.jpg', 'wb') as wf:
chunk_size = 4096
rf_chunk = rf.read(chunk_size)
while len(rf_chunk)>0:
wf.write(rf_chunk)
rf_chunk = rf.read(chunk_size)
"""
"""
for line in rf:
wf.write(line)
"""