tempnam()方法的返回一个唯一的路径名称,用于创建一个临时文件。
语法
以下是 tempnam()方法的语法:
os.tempnam(dir, prefix)
参数
-
dir -- 这是临时文件的名称将要创建的目录
-
prefix -- 这是在产生临时文件名的前缀
返回值
该方法返回一个唯一的路径。
示例
下面的例子显示 tempnam()方法的使用。
# !/usr/bin/python3 import os, sys # prefix is tuts1 of the generated file tmpfn = os.tempnam('/tmp/tutorialsdir,'tuts1') print "This is the unique path:" print tmpfn
当我们运行上面的程序,它会产生以下结果:
This is the unique path: /tmp/tutorialsdir/tuts1IbAco8
上一篇:
Python3文件方法
下一篇:
Python3 os文件目录的方法