Python的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)
當運行上述程式時,它將在/tmp
目錄中創建一個符號鏈接,如下所示: -
This is the unique path:
/tmp/tutorialsdir/tuts1IbAco8
上一篇:
Python os模組方法
下一篇:
Python異常處理