python open does not create file if it doesnt exist

Posted by Toddeman on Stack Overflow See other posts from Stack Overflow or by Toddeman
Published on 2010-06-03T15:05:54Z Indexed on 2010/06/03 15:14 UTC
Read the original article Hit count: 181

Filed under:
|

I am using Python.

What is the best way to open a file in rw if it exists, or if it does not, then create it and open it in rw? From what i read, file = open('myfile.dat', 'rw') should do this, no? it is not working for me (python 2.6.2) and im wondering if it is a version problem, or not supposed to work like that or what.

The bottom line is, i just need a solution for the problem. I am curious about the other stuff, but all i need is a nice way to do the opening part.

thanks in advance

© Stack Overflow or respective owner

Related posts about python

Related posts about file-io