Python的tempnam()
方法返回建立臨時檔案的唯一路徑名。
語法
以下是tempnam()
方法的語法 -
os.tempnam(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