Python os.tempnam() method
Python OS file/directory methods
Overview
The os.tempnam() method returns a unique pathname for creating a temporary file.
Syntax
The syntax of the **tempnam()** method is as follows:
os.tempnam(dir, prefix)
Parameters
-
dir -- the path of the temporary file to create.
-
prefix -- the temporary file prefix
Return Value
This method returns a unique path.
Example
The following example demonstrates the use of the tempnam() method:
Example
#!/usr/bin/python
-- coding: UTF-8 --
import
os
,
sys
A file with the prefix runoob
tmpfn
=
os
.
tempnam
(
'/tmp/runoob'
,
'runoob'
)
"This is a unique path:"
tmpfn
The output of the above program is:
This is a unique path:
/tmp/runoob/runoobIbAco8