python – What does the w mean in open(filename, w)?

python – What does the w mean in open(filename, w)?

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 youre using (i.e., read-only, writable). In this case, its to be able to (w)rite to the file.

https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files

python – What does the w mean in open(filename, w)?

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

Leave a Reply

Your email address will not be published. Required fields are marked *