-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path38_Read_Files.py
More file actions
41 lines (33 loc) · 793 Bytes
/
Copy path38_Read_Files.py
File metadata and controls
41 lines (33 loc) · 793 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
38
39
40
41
# Open a File on the Server and read
f = open("Demofile.txt", "r")
print(f.read())
"""
# Open from a different location (Fixed path)
f = open(r"D:\Python\Python-learning\07_File_Handling\Demofile.txt", "r")
print(f.read())
Commenting for better run
"""
#------------------->
#Read Only Parts of the File
#Return first 5 chracter of the file
f = open("Demofile.txt", "r")
print(f.read(5))
#Opening with
with open("Demofile.txt", "r") as b:
print(b.read())
#Read lines
#Read 1 line
f = open("demofile.txt", "r")
print(f.readline())
#Read 2 lines
f = open("demofile.txt", "r")
print(f.readline())
print(f.readline())
#Loop through the file line by line
f = open("Demofile.txt", "r")
for x in f:
print(x)
#Close Files
f = open("Demofile.txt", "r")
print(f.readline())
f.close()