Python Basic Learning Note--python Basic Tutorial (2nd Edition revision) Chapter 11th (Documents and materials)

Source: Internet
Author: User

#文件模式 Open (name[.mode[.buffering])

rwab+f=open (R'c:\text\somefile')

#基本文件方法

#对文件内容进行迭代

F=open ('somefile.txt','w')  #R is the default F.write ('hello') f.read (4) f.close ()

#管式输出

$ cat Somefile.txt|python Somescript.py|sort

#读写行

Writelinesreadlines

#关闭文件

#对文件进行迭代

processing by bytes F=open (filename) whileTrue:char=f.read (1)         if  notChar Breakprocess (char) f.close ()#action by Rowf=open (filename) whileTrue:line=F.readline ()if  notLine Breakprocess (line)#Read all contentf=open (filename) forCharinchF.read (): Process (char)ImportFileinput forLineinchFileinput.input (FILENAMR) process (line) $ iteration File forLine inf:process (line)
# open a file and return the file object # Alias for file

Python Basic Learning Note--python Basic Tutorial (2nd Edition revision) Chapter 11th (Documents and materials)

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.