tags:

views:

306

answers:

4

In the python built-in open function, what is the exact difference between the modes w, a, w+, a+?

+4  A: 

the opening modes are exacltly the same that C fopen() std library function.

This is a reference.

AlberT
I believe you mean the fopen call in the C standard library (which is not a system call)
Eli Courtwright
+2  A: 

The options are the same as for the fopen function in the C standard library:

w truncates the file, overwriting whatever was already there

a appends to the file, adding onto whatever was already there

w+ opens for reading and writing, truncating the file but also allowing you to read back what's been written to the file

a+ opens for appending and reading, allowing you both to append to the file and also read its contents

Eli Courtwright
+1  A: 

What these flags means is explained in the documentation. http://docs.python.org/library/functions.html#open

Lennart Regebro
always going to upvote the answer that references the language itself, -- and not some other esoteric pretender ;)
KevinDTimm
@kevindtimm: What do you do for a question which references the answer as part of the question? Upvote it also?
S.Lott
@S.Lott: Ha, you are right. He links to the docs. I didn't see that.Then I don't understand the question. His answer is in the doc that he links to.
Lennart Regebro
@S. Lott, like Lennart, I didn't see that the OP was illiterate (the link was not obvious in his post).
KevinDTimm
A: 
shubham