參考自 這裡
Preface :
This module generates temporary files and directories. It works on all supported platforms.
In version 2.3 of Python, this module was overhauled for enhanced security. It now provides three new functions, NamedTemporaryFile(), mkstemp(), and mkdtemp(), which should eliminate all remaining need to use the insecure mktemp() function. Temporary file names created by this module no longer contain the process ID; instead a string of six random characters is used.
Also, all the user-callable functions now take additional arguments which allow direct control over the location and name of temporary files. It is no longer necessary to use the global tempdir and template variables.
Supported APIs :
The module defines the following user-callable functions :
- tempfile.TemporaryFile([mode='w+b'[, bufsize=-1[, suffix=''[, prefix='tmp'[, dir=None]]]]])
- tempfile.NamedTemporaryFile([mode='w+b'[, bufsize=-1[, suffix=''[, prefix='tmp'[, dir=None[, delete=True]]]]]])
- tempfile.SpooledTemporaryFile([max_size=0[, mode='w+b'[, bufsize=-1[, suffix=''[, prefix='tmp'[, dir=None]]]]]])
- tempfile.mkstemp([suffix=''[, prefix='tmp'[, dir=None[, text=False]]]])
- tempfile.mkdtemp([suffix=''[, prefix='tmp'[, dir=None]]])
Global Variables :
The module uses two global variables that tell it how to construct a temporary name. They are initialized at the first call to any of the functions above. The caller may change them, but this is discouraged; use the appropriate function arguments, instead.
- tempfile.tempdir
- tempfile.gettempdir()
- tempfile.gettempprefix()
Supplement :
* [Python Std Library] Built-in Types : File Objects
* stackoverflow > TypeError: 'str' does not support the buffer interface
Preface :
This module generates temporary files and directories. It works on all supported platforms.
In version 2.3 of Python, this module was overhauled for enhanced security. It now provides three new functions, NamedTemporaryFile(), mkstemp(), and mkdtemp(), which should eliminate all remaining need to use the insecure mktemp() function. Temporary file names created by this module no longer contain the process ID; instead a string of six random characters is used.
Also, all the user-callable functions now take additional arguments which allow direct control over the location and name of temporary files. It is no longer necessary to use the global tempdir and template variables.
Supported APIs :
The module defines the following user-callable functions :
- tempfile.TemporaryFile([mode='w+b'[, bufsize=-1[, suffix=''[, prefix='tmp'[, dir=None]]]]])
- tempfile.NamedTemporaryFile([mode='w+b'[, bufsize=-1[, suffix=''[, prefix='tmp'[, dir=None[, delete=True]]]]]])
- tempfile.SpooledTemporaryFile([max_size=0[, mode='w+b'[, bufsize=-1[, suffix=''[, prefix='tmp'[, dir=None]]]]]])
- tempfile.mkstemp([suffix=''[, prefix='tmp'[, dir=None[, text=False]]]])
- tempfile.mkdtemp([suffix=''[, prefix='tmp'[, dir=None]]])
Global Variables :
The module uses two global variables that tell it how to construct a temporary name. They are initialized at the first call to any of the functions above. The caller may change them, but this is discouraged; use the appropriate function arguments, instead.
- tempfile.tempdir
- tempfile.gettempdir()
- tempfile.gettempprefix()
Supplement :
* [Python Std Library] Built-in Types : File Objects
* stackoverflow > TypeError: 'str' does not support the buffer interface
This message was edited 28 times. Last update was at 11/05/2012 09:49:01
沒有留言:
張貼留言