"sandorf" <fa*********@gm ail.com> wrote:
I'm new to python. Have a simple question.
"open" function can only open an existing file and raise a IOerror when
the given file does not exist. How can I creat a new file then?
reading the documentation might help:
help(open)
class file(object)
| file(name[, mode[, buffering]]) -> file object
|
| Open a file. The mode can be 'r', 'w' or 'a' for reading (default),
| writing or appending. The file will be created if it doesn't exist
| when opened for writing or appending; it will be truncated when
| opened for writing. Add a 'b' to the mode for binary files.
| Add a '+' to the mode to allow simultaneous reading and writing.
/snip/
| Note: open() is an alias for file().
this is also explained in the chapter 7 of the tutorial ("reading and writing files"),
as well as the reference manual.
</F>