-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiles.py
More file actions
23 lines (15 loc) · 744 Bytes
/
files.py
File metadata and controls
23 lines (15 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fileHandle = open('../../files/text.file', 'r')
# To iterate thru the sequence of lines in the file use a for statement.
# The print statement adds a new line to each line to remove the extra space use rstrip()
# new line is considered as extra white space and is stripped.
for line in fileHandle:
print('{}{}{}'.format('printing line and length of file:', line.rstrip(), len(line)))
# Reading the whole file using the length of the file
fileHandle = open('../../files/text.file')
readLine = fileHandle.read()
print('length of the file:{}'.format(len(readLine)))
print('{}{}'.format('readLine::', readLine[:39]))
fileHandle.close()
# Reading all lines
fd = open('../../files/text.file', 'r')
print(f"lines are:::{fd.readlines()}")