Python file operations

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.