Learn Python's actions on file content

Source: Internet
Author: User

The operation of the file in Python uses open (filename, "w"), where filename is the file name, w refers to the write operation, it automatically overwrites all the contents of the file, as well as R read operations and a append operation.

Note that: Only one operation can be done at the same time, such as writing the time can not be read, even if you use the w+ parameter, but also just read out the blank content, but will not error, all completed an operation using the new parameters to continue different operations, such as:

f = open (filename, ' W ') #以写操作打开文件filename, the file exists then is overwritten, does not exist then establishes the F.write (' This is a test ') #执行写操作, writes the content is a testf = open (file Name) #再次以读操作打开文件filename, there is no add parameter, and the ' A ' action print f.readline () #输出读取的内容 is added by default.

This article is from the "Rickyhul" blog, make sure to keep this source http://rickyh.blog.51cto.com/10934856/1912875

Learn Python's actions on file content

Related Article

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.