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