Python file Read and write method: Read ReadLine readlines wirte writelines

Source: Internet
Author: User


The Read () method reads the entire file and returns the entire file as a string.


The ReadLine () method reads only one line at a time, one line at a time, per run. If you want to read the entire file, you need to combine loops to determine the end of the file.

Python determines that the flag at the end of the file is read to a null character.


Like what:

While str! = ": ReadLine ()


Instead, ReadLines () reads the entire file, returns it as a list, and takes each line of the file as an element of the list.


The Write (str) parameter is a string that writes a string to the file.


Writelines (SEQ) provides parameters that can iterate over objects, such as lists, to write a list to a file. Similar to writing to each element called write (str) writes the file.


After writing the file, you need to call flush () to persist to the disk.








This article is from the Linux and networking blogs, so be sure to keep this source http://khaozi.blog.51cto.com/952782/1769531

Python file Read and write method: Read ReadLine readlines wirte writelines

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.