Python3 os.tmpnam()方法

tmpnam()方法返回一个唯一的路径名称,用于创建一个临时文件。

语法

下面是使用 tmpnam()方法的语法:
os.tmpnam()

参数

  • NA

返回值

这个方法返回一个唯一的路径名。

示例

下面的例子说明了如何使用使用 tmpnam()方法。
# !/usr/bin/python3

import os, sys

# Temporary file generated in current directory
tmpfn = os.tmpnam()

print "This is the unique path:"
print tmpfn
当我们运行上面的程序,它会产生以下结果:
This is the unique path:
/tmp/fileUFojpd


上一篇: Python3文件方法 下一篇: Python3 os文件目录的方法