-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreading_files.py
More file actions
21 lines (17 loc) · 789 Bytes
/
reading_files.py
File metadata and controls
21 lines (17 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import os
employee_file = open("../MiscFiles/employees.txt", "r") # This will parse the file to the interpreter in 'read' mode.
# 'Read' and 'Write' modes in the context of the 'open' statement are denoted by 'r' and 'w' respectively.
print(employee_file.readable()) # The '.readable()' method tells you if the affected file is readable (via 'r' above).
employees = []
for employee in employee_file.readlines(): # This will loop over each line and print it.
employees.append(employee.split(","))
employee_file.close()
print(employees)
with open("../MiscFiles/employees.txt") as file:
while line := file.readline():
print(line.rstrip(",\n"))
while os.path.isfile("../MiscFiles/test.txt") is False:
print("This is false")
break
else:
print("This is true")