Python3 os.tmpnam()方法

tmpnam()方法返回一個唯一的路徑名稱,用於創建一個臨時檔。

語法

下麵是使用 tmpnam()方法的語法:
os.tmpnam()

參數

  • NA

返回值

這個方法返回一個唯一的路徑名。

示例

下麵的例子說明了如何使用使用 tmpnam()方法。
# !/usr/bin/python3

import os, sys

# Temporary file generated in current directory
tmpfn = os.tmpnam()

print "This is the unique path:"
print tmpfn
當我們運行上面的程式,它會產生以下結果:
This is the unique path:
/tmp/fileUFojpd


上一篇: Python3檔方法 下一篇: Python3 os檔目錄的方法