os.tmpfile()

G

Guest

Can anyone elaborate on how 'os.tmpfile()' works? I was thinking it would create some sort of temporary file I could quickly add text too and then when I was finished would automatically get rid of it. Here's my questions:

1. Does it actually create a file somewhere? If so, where does it store it? Does it have to manually be deleted afterwards?
3. How do you use it? I tried the following, but it doesn't seem to work:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/posixpath.py", line 171, in exists
TypeError: coercing to Unicode: need string or buffer, file foundTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/posixpath.py", line 112, in basename
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/posixpath.py", line 77, in split
AttributeError: 'file' object has no attribute 'rfind'.... print x
....
Can you actually 'write' to this file? And if so, do you have to 'close()' it when you're done with it? Thanks for your help with this... I'm still learning Python and haven't been able to find out much about this in the documentation or on-line.

Jay
 
E

Erik Max Francis

Can anyone elaborate on how 'os.tmpfile()' works? I was thinking it would create some sort of temporary file I could quickly add text too and then when I was finished would automatically get rid of it. Here's my questions: ...
Can you actually 'write' to this file? And if so, do you have to 'close()' it when you're done with it? Thanks for your help with this... I'm still learning Python and haven't been able to find out much about this in the documentation or on-line.

It's a file. You read strings from it and write strings to it. It
isn't a string itself. Given that what you're trying to do doesn't make
any sense, it's hard to know where to begin to identify what's confusing
you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,196
Latest member
ScottChare

Latest Threads

Top