Python cycle 5
Python cycle 5
1. Write a Python program to read a file line by line and store it into a list.
f1=open("demo1.txt",'w')
f1.write
("This the new file i have created\n here is the second line\n each line
in a list")
f1.close()
f=open("demo1.txt",'r')
lines=[]
for line in f:
lines.append(line.strip())
print(lines)
output
p
2. Python program to copy odd lines of one file to other
source_file = "source_file.txt"
destination_file = "destination_file.txt"
print(lines)
Output
3. Write a Python program to read each row from a given csv file and print a list of
strings.
output
4. Write a Python program to read specific columns of a given CSV file and print the
content of the columns.
OUTPUT