Python open file can have multiple modes

Source: Internet
Author: User

First, the Python open file can have a variety of modes, read mode, write mode, append mode, while reading and writing mode, and so on, here mainly introduces the mode of simultaneous reading and writing r+

Python opens the file by using the Open method

file_handler =open(filename,mode)

Mode has the following types of modes


R
Open the file as read to read the file information.
W
Open a file in write mode to write information to the file. If the file exists, empty the file, and then write the new content
A
Open a file in Append mode (that is, an open file, the file pointer is automatically moved to the end of the file), and if the file does not exist, create
r+
The file can be read and written by opening the file in read/write mode.
w+
Remove the file contents, and then open the file as read-write.
A +
Open the file in read-write mode and move the file pointer to the end of the file.
B
Open the file in binary mode instead of in text mode. This mode is only valid for Windows or DOS, and Unix-like files are operated in binary mode.

So to open the file in both read and write mode, you can use r+

Python open file can have multiple modes

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.