What does the "w" mean in open(filename, "w")? [duplicate]

I'm reading Exercise 16 of "Learn Python The Hard way" and I'm confused about open(filename, "w") -- what does the "w" mean?

0

4 Answers

w stands for writing permission for the opened file

open(name[, mode[, buffering]]) 

Looking at the signature we can (often) understand what each argument does more info here

The second argument in opening a filename represents the mode you're using (i.e., read-only, writable). In this case, it's to be able to (w)rite to the file.

The "W" means that you are opening the file called filename with the purpose of writing to it(hence the "W" for write.)

The "w" specifies that the file is being written to. As you can see here, "w" is the mode that you use when writing to a file.

The most commonly-used values of mode are 'r' for reading, 'w' for writing (truncating the file if it already exists)...

You Might Also Like