Text File - Programs
Text File - Programs
WAP to read 30 bytes from a text file and then read another 30 characters from
the last position read.
1 f = open ("<file_name_with_extension>")
2 s = f.read ()
3 print (s)
4 myfile.close ()
1 f1 = open ("Alphabet_line.txt")
2 s = f1.readlines()
3 print ("The number of lines is", len(s))
4 f1.close()
7. WAP to obtain the roll number, names and marks of students from the user and
store these in a new file called “Marks.txt” .
1 f = open ("Marks.txt")
2 while str :
3 str = f.readline ()
4 print (str)
5 f.close ()
10. WAP to read a text file line by line and display each word separated by a ‘#’ .
12. WAP to remove all the lines that contain the character 't' in a file and write it to
another file.