Python os.tempnam() 方法



Python 方法tempnam() 返回一個用於建立臨時檔案的唯一路徑名。

從 Python 3.0 版本開始,os.tempnam() 方法已被棄用。

語法

以下是 Python os.tempnam() 方法的語法:

os.tempnam(dir, prefix)

引數

Python os.tempnam() 接受以下引數:

  • dir - 這是將建立臨時檔名所在的目錄。

  • prefix - 這是生成的臨時檔名的字首。

返回值

Python os.tempnam() 方法返回一個唯一的路徑。

示例

以下示例顯示了 tempnam() 方法的用法。

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
os_file_methods.htm
廣告
© . All rights reserved.