Python 方法 tempnam() 返回一个唯一的路径名,该路径名对于创建临时文件来说是合理的。
随着 Python 3.0 版本的发布,os.tempnam() 方法已被弃用。
语法
以下是 Python os.tempnam() 方法的语法 -
os.tempnam(dir, prefix)
参数
Pythonos.tempnam() 接受以下参数 -
- dir − 这是将在其中创建临时文件名的目录。
- prefix - 这是生成的临时文件名的前缀。
返回值
Python os.tempnam() 方法返回唯一路径。
例以下示例显示了 tempnam() 方法的用法。
import os, sys
# prefix is tuts1 of the generated file
tmpfn = os.tempnam("/tmp/qikepudir,'tuts1'")
print ("This is the unique path:")
print (tmpfn)
当我们运行上述程序时,它会产生以下结果——
This is the unique path:
/tmp/
/tmp/
qikepudir
/tuts1IbAco8