I'm reading Exercise 16 of "Learn Python The Hard way" and I'm confused about open(filename, "w") -- what does the "w" mean?
Asked
Active
Viewed 2.2k times
0
Jon Clements
- 132,101
- 31
- 237
- 267
chandler11able
- 123
- 1
- 1
- 7
4 Answers
1
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.
https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files
thumbtackthief
- 5,936
- 8
- 37
- 80
1
The "W" means that you are opening the file called filename with the purpose of writing to it(hence the "W" for write.)
Benjamin D
- 11
- 1
1
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)...
A.J. Uppal
- 18,339
- 6
- 41
- 73