Python方法tempnam()返回用于创建临时文件的唯一路径名。
os.tempnam(dir, prefix)
dir - 这是将在其中创建临时文件名的目录。
prefix - 这是生成的临时文件名的前缀。
此方法返回唯一的路径。
链接:https://www.learnfk.comhttps://www.learnfk.com/python/os-tempnam.html
来源:LearnFk无涯教程网
以下示例显示tempnam()方法的用法。
# !/usr/bin/python import os, sys # 前缀是生成文件的 tuts1 tmpfn=os.tempnam('/tmp/Learnfkdir,'tuts1') print "This is the unique path:" print tmpfn
当无涯教程运行上面的程序时,它产生以下输出-
This is the unique path: /tmp/Learnfkdir/tuts1IbAco8
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)