Python os.tmpfile()方法

2019-10-16 23:05:15

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

語法

以下是tmpnam()方法的語法 -

os.tempnam(dir, prefix)

引數

  • 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