Python os.tempnam() Method
Advertisements
Description
The method tempnam() returns a unique path name that is reasonable for creating a temporary file.
Syntax
Following is the syntax for tempnam() method
os.tempnam(dir, prefix)
Parameters
dir -- This is the dir where the temporary filename will be created.
prefix -- This is the prefix of the generated temporary filename.
Return Value
This method returns a unique path.
Example
The following example shows the usage of tempnam() method.
# !/usr/bin/python
import os, sys
# prefix is tuts1 of the generated file
tmpfn = os.tempnam('/tmp/tutorialsdir,'tuts1')
print "This is the unique path:"
print tmpfn
Let us compile and run the above program, this will produce the following result:
This is the unique path: /tmp/tutorialsdir/tuts1IbAco8