简体   繁体   中英

opening a file in “a+” mode in python 2.7

Append usually means saying "Start at the end of the file"

"+" is added in the mode parameter in open(filename, [mode], [buffering]) to allow both read and write operations

Now if I use "r+" it means "Start at the beginning and allow both read and write operations"

And for "a+" it should mean "Start at the end and allow both read and write operations" ; But this is not the case. For "a+" it starts at the beginning and allow read write operations.

So this means there is no difference between "r+" and "a+" .

Basically, a+ , reads from beginning but writes to the end and a+ will create the file if it does not exist.

Since opening file in Python is almost identical in C you can take a look at this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM