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
上一篇:
Python3檔方法
下一篇:
Python3 os檔目錄的方法