描述
方法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
相關用法
- Python 3 os.tcgetpgrp()用法及代碼示例
- Python 3 os.tmpfile()用法及代碼示例
- Python 3 os.tmpnam()用法及代碼示例
- Python 3 os.tcsetpgrp()用法及代碼示例
- Python 3 os.ttyname()用法及代碼示例
- Python 3 os.fstatvfs()用法及代碼示例
- Python 3 os.minor()用法及代碼示例
- Python 3 os.close()用法及代碼示例
- Python 3 os.unlink()用法及代碼示例
- Python 3 os.major()用法及代碼示例
- Python 3 os.rmdir()用法及代碼示例
- Python 3 os.fdopen()用法及代碼示例
- Python 3 os.fdatasync()用法及代碼示例
- Python 3 os.isatty()用法及代碼示例
- Python 3 os.rename()用法及代碼示例
- Python 3 os.walk()用法及代碼示例
- Python 3 os.renames()用法及代碼示例
- Python 3 os.makedirs()用法及代碼示例
- Python 3 os.utime()用法及代碼示例
- Python 3 os.statvfs()用法及代碼示例
注:本文由純淨天空篩選整理自 Python 3 - os.tempnam() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。