1 #author F2 3 ImportSys,time4 5 6f = open ("file","R", encoding="Utf-8")7 8 Print(F.tell ())9 Print(F.readline (). Rstrip ())Ten Print(F.read (5)) One Print(F.tell ()) A Print(F.read ()) - Print("Split Line". Center (50,"-")) - Print(F.readline ())#empty line pointer has no content at the end theF.seek (0)#pointer Reset - Print(F.readline ()) - - + Print(f.encoding)#encoding of the file - Print(F.fileno ())#returns the number of the file + Print(F.seekable ())#determine if a file can be moved A Print(F.readable ())#determine if a file is readable at Print(F.writable ())#determine if the file is writable - Print(f.closed)#determine if the file is closed - - #print (F.flush ()) #刷新 memory cache forced flush (real-time flush to hard disk) - Print(dir (f.buffer)) - in ##演示进度条 - forIinchRange (50): toSys.stdout.write ("#") + Sys.stdout.flush () -Time.sleep (0.1) the * #f.truncate () #截断 not specified, starting from 0 truncation specified--the stage length is not moving so that it is truncated from the beginning $ Panax Notoginseng f.close () - the #file = open ("File", "w+", encoding= "Utf-8") #写读模式打开 + #file = open ("File", "A +", encoding= "Utf-8") #追加读模式打开 A #file = open ("File", "RB") #二进制读模式打开 Video (Network transfer: socket) the #file = open ("File", "RB") #二进制写模式打开 Video (Network transfer: socket) character->encode-> binary + #file = open ("File", "RU", encoding= "Utf-8") #linux和win中回车自动转换 -File = Open ("file","r+", encoding="Utf-8")#read/write mode open $ Print(File.readline ()) $ Print(File.readline ()) - Print(File.readline ()) -File.write ("-------------")#the results are written at the end of the document the -File.close ()
Python file operations