File tree 2 files changed +26
-10
lines changed 2 files changed +26
-10
lines changed Original file line number Diff line number Diff line change 1
1
#Write a Python program to read a file line by line and store it into a list.
2
-
2
+ """
3
3
fn = open("demo.txt",'r') #run in thonny (filename,mode)
4
4
s= fn.readline() # for read line by line
5
5
print(s)
6
6
fn.close()
7
7
print(fn.closed) #file close status
8
8
print(fn.mode) #file mode
9
9
print(fn.name) #file name
10
-
11
-
12
10
fo =open("demo2.txt","w")
13
-
14
11
fo.write("Python is dynamically-typed and garbage-collected \n . It supports multiple programming paradigms")
15
12
fo.close()
16
-
17
- """ #replace data in file
13
+ #replace data in file
18
14
f2 =open("demo2.txt","w")
19
15
f2.write("Python gdgg")
20
16
f2.close()
17
+
21
18
"""
22
19
23
20
fn1 = open ("demo2.txt" ,"r" )
24
- s1 = fn1 .readline ()# read multiple line
21
+ # read multiple line
22
+ """
23
+ s1 =fn1.readline()
25
24
s2 =fn1.readline()
26
-
25
+ s3 =fn1.readline()
27
26
print(s1)
28
27
print(s2)
28
+ print(s3)
29
+ """
30
+
31
+
32
+
33
+ """
34
+ for x in range(0,len(s1)):
35
+ print(s1[x])
29
36
fn1.close()
37
+ """
38
+ """
39
+ #readlines
40
+ s1 =fn1.readlines()
41
+ print(s1)
42
+ """
43
+ #as list comp
30
44
45
+ print ([line .strip () for line in open ('demo2.txt' ,'r' )])
31
46
32
47
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments