[Tutor] creating files on open()

William O'Higgins william.ohiggins at utoronto.ca
Fri May 20 21:10:43 CEST 2005


On Fri, May 20, 2005 at 01:48:19PM -0500, Kristian Zoerhoff wrote:
>On 5/20/05, William O'Higgins <william.ohiggins at utoronto.ca> wrote:
>> When I am open()-ing a file, I sort of expect that if the file doesn't
>> exist that it would be created, but it doesn't, it whines about it
>> instead.  So, how do I create a file with Python?  I've looked all over,
>> but I'm obviously missing something.  Thanks.
>
>How are you opening the file? It will be created if you open in write
>or append mode (w or a), but not in read-only (r) mode.

Fascinating.  I was opening the file read-write (r+) and it didn't work.
Are there only the few file-access methods (read (r), write (w), append
(a) and read-write (r+))?  Sometimes I like to prepend or to clobber or
to address in binary mode - are these things possible, or do I have to
seek() to prepend and delete to clobber?  Thanks.
-- 

yours,

William

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.python.org/pipermail/tutor/attachments/20050520/a85eacf1/attachment.pgp


More information about the Tutor mailing list