-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadFile.py
47 lines (36 loc) · 822 Bytes
/
readFile.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
44
45
46
47
# File Objects
"""
f = open('test.txt', 'r')
print(f.mode)
f.close()
"""
"""
with open('test.txt', 'r') as f:
# Do nothing
pass
print(f.closed)
"""
# Open File
with open('test.txt', 'r') as f:
# Sets size to read
sizeToRead = 4
# Store File Chunk in an object
f_contents = f.read(sizeToRead)
#Read() with no args passed reads entire file. You're fault if you don't have enough RAM
#f_contents = f.read()
# States current position of file
#print(f.tell())
# Loop Through File Object
while len (f_contents)>0:
print (f_contents, end='')
f_contents = f.read(sizeToRead)
"""
with open('test.txt', 'r') as f:
f_contents = f.readline()
print(f_contents)
"""
"""
with open('test.txt', 'r') as f:
for line in f:
print(line, end='')
"""