write()
Andy Salnikov
a_salnikov at yahoo.com
Sun Jul 30 03:01:34 EDT 2006
"manuhack" <manuhack at gmail.com> wrote in message
news:1153981114.837884.232610 at p79g2000cwp.googlegroups.com...
>I copied the lines
>
> f=open('/tmp/workfile', 'w')
> print f
> f.close()
>
> from Python 2.4 Documentation 7.2. But it said IOerror No such file or
> directory" '/tmp/workfile'
>
> Is it something about the os? I'm using Python 2.4 under WinXP.
> Thanks. Without / I can open it.
>
In addition to what others said, if you need to open a temporary file,
it's better to use os.tmpfile() to get a file descriptor and not to
rely on magic file names like '/tmp/workfile'. So instead of open()
you should do:
import os
f = os.tmpfile()
This should work fine of both Windows and UNIX systems.
Andy.
More information about the Python-list
mailing list