Skip to content

Commit 8fbf8f2

Browse files
committed
multiple line print
readlines
1 parent 321be6b commit 8fbf8f2

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

C05/co5_p1.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
11
#Write a Python program to read a file line by line and store it into a list.
2-
2+
"""
33
fn = open("demo.txt",'r') #run in thonny (filename,mode)
44
s= fn.readline() # for read line by line
55
print(s)
66
fn.close()
77
print(fn.closed) #file close status
88
print(fn.mode) #file mode
99
print(fn.name) #file name
10-
11-
1210
fo =open("demo2.txt","w")
13-
1411
fo.write("Python is dynamically-typed and garbage-collected \n. It supports multiple programming paradigms")
1512
fo.close()
16-
17-
""" #replace data in file
13+
#replace data in file
1814
f2 =open("demo2.txt","w")
1915
f2.write("Python gdgg")
2016
f2.close()
17+
2118
"""
2219

2320
fn1 =open("demo2.txt","r")
24-
s1 =fn1.readline()# read multiple line
21+
# read multiple line
22+
"""
23+
s1 =fn1.readline()
2524
s2 =fn1.readline()
26-
25+
s3 =fn1.readline()
2726
print(s1)
2827
print(s2)
28+
print(s3)
29+
"""
30+
31+
32+
33+
"""
34+
for x in range(0,len(s1)):
35+
print(s1[x])
2936
fn1.close()
37+
"""
38+
"""
39+
#readlines
40+
s1 =fn1.readlines()
41+
print(s1)
42+
"""
43+
#as list comp
3044

45+
print([line.strip() for line in open('demo2.txt','r')])
3146

3247

C05/demo2.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
Python is dynamically-typed and garbage-collected
2-
. It supports multiple programming paradigms
1+
1.Python is dynamically-typed and garbage-collected
2+
2.It supports multiple programming paradigms
3+
3.Object-oriented and functional programming

0 commit comments

Comments
 (0)