-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReading Files.py
32 lines (17 loc) · 1.08 KB
/
Reading Files.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
emp_file = open("employees.txt", "r") ## Read file
# open("employees.txt", "w") ## Write to file
# open("employees.txt", "a") ## Append to file (Can't change anything, Only appending to file)
# open("employees.txt", "r+") ## Read from and write to file
print(emp_file.readable()) ## True
print(" ")
print(" ")
## print(emp_file.read()) ## Read the entire file
print(" ")
print(" ")
print(emp_file.readline()) ## Read the first line
print(" ")
print(" ")
print(emp_file.readlines()) ## Read all lines and put them in an array
## ['Casillas - Manager\n', 'Ronaldo - Footballer\n', 'Modric - Artist\n']
## Important Note: Using .readline() after .read() will print nothing
emp_file.close()