Python File access mode

Source: Internet
Author: User

f = open ('xxx file ' access mode ')
  • r Opens the file in read-only mode (read). The pointer to the file will be placed at the beginning of the file. The default mode.
  • W opens a file for writing only (write). Overwrite the file if it already exists or create a new file if the file does not exist
  • a opens a file for appending. If the file already exists, the file pointer will be placed at the end of the file. In other words, the new content will be written to the existing content. If the file does not exist, create the file and write it.
  • RB opens a file in binary format for read-only. The file pointer will be placed at the beginning of the file. The default mode.
  • WB Opens a file in binary format for writing only. Overwrite the file if it already exists, or create a new file if the file does not exist.
  • AB opens a file in binary format for appending. If the file already exists, the file pointer will be placed at the end of the file. In other words, the new content will be written to the existing content. If the file does not exist, create the file and write it.
  • r+ Open a file for read-write. The file pointer will be placed at the beginning of the file. If the file does not exist, the program will crash.
  • w+ Open a file for read-write. Overwrite the file if it already exists, or create a new file if the file does not exist.
  • A + opens a file for appending. If the file already exists, the file pointer will be placed at the end of the file. The file opens with an append mode. If the file does not exist, create the file for read-write.
  • rb+ opens a file in binary format for read-write. The file pointer will be placed at the beginning of the file.
  • wb+ opens a file in binary format for read-write. Overwrite the file if it already exists, or create a new file if the file does not exist.
  • ab+ opens a file in binary format for appending. If the file already exists, the file pointer will be placed at the end of the file.

Python File access mode

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.