How Python files are processed

Source: Internet
Author: User

Open file: File (' Test.tx ', ' RB '), if not plus mode, the default is read-only mode to open files.

Open File Mode:

1. W: Open file in write-only mode

2. R: Open file in read-only mode

3. A: Open file in Append mode

4. r+: Open in read/write mode

5. w+: Open in read-write mode

6. A +: Open in additional read mode


Close file: f.close, File Open, after processing, be sure to remember to close the file.


File Common methods

F.readline (): reads a row

F.readlines (): Read all rows of the file

F.write ("): Write File

F.strip (): Stripping spaces and newline characters, S.strip (' \ n ') means stripping line breaks

F.split (): Separated by a space, F.split (': ') denotes ":" As the delimiter

F.flush: Updating files (writing files from memory)

F.seek (0): Back to the beginning of the file

This article is from the "Spark" blog, be sure to keep this source http://154883753.blog.51cto.com/470223/1733285

How Python files are processed

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.