Please) try: all_the_textfile_object.read () finally: file_object.close () 2. read fixed byte file_objectopen (abinfile, rb) try: whileTrue:... 1. open the file and read all content
File_object = open('thefile.txt ')
Try:
All_the_text = file_object.read ()
Finally:
File_object.close ()
2. read fixed bytes
File_object = open ('abinfile', 'RB ')
Try:
While True:
Chunk = file_object.read (100)
If not chunk:
Break
Do_something_with (chunk)
Finally:
File_object.close ()
3. read a row of files
F = open ("D: \ test \ BlueSoftSetup. log", "r ")
Try:
While True:
Line = f. readline ()
If line:
Print (line)
Else:
Break;
Finally:
F. close ();
4. write files
Write a text file
Output = open ('data', 'w ')
Write binary files
Output = open ('data', 'WB ')
Append a file
Output = open ('data', 'W + ')
Write Data
File_object = open('thefile.txt ', 'w ')
File_object.write (all_the_text)
File_object.close ()