Bases: object
Weak replacement for the Python’s tempfile.TemporaryFile.
This class is a replacment for tempfile.NamedTemporaryFile() but will work also with Windows 7/Vista’s UAC.
Parameters: |
---|
Example
>>> with NamedTemporaryFile() as tf:
... tf._fileobj
... tf.write("test")
... os.path.exists(tf.name)
<open file '<fdopen>', mode 'w+b' at 0x...>
True
>>> # when using the with statement, the file is deleted at the end:
>>> os.path.exists(tf.name)
False
>>> with NamedTemporaryFile() as tf:
... filename = tf.name
... with open(filename, 'wb') as fh:
... fh.write("just a test")
... with open(filename, 'r') as fh:
... print fh.read()
just a test
>>> # when using the with statement, the file is deleted at the end:
>>> os.path.exists(tf.name)
False
Attributes
__dict__ | |
__doc__ | str(object=’‘) -> string |
__module__ | str(object=’‘) -> string |
__weakref__ | list of weak references to the object (if defined) |
Special Methods
__enter__ | |
__exit__ | |
__getattr__ | |
__init__ |