[英]Are tempfile.TemporaryFile and tempfile.NamedTemporaryFile same in Python > 3
import tempfile
print(help(tempfile.TemporaryFile))
print(help(tempfile.NamedTemporaryFile))
上面的2條語句給出與輸出相同的東西,它們是否都屬於同一類NamedTemporaryFile
tp = tempfile.TemporaryFile(suffix="xyz.txt", prefix="abc",
dir="C:/bin/", mode='w',
buffering=-1, delete=False)
print(tp)
tp.close()
tp = tempfile.NamedTemporaryFile(suffix="pqr.txt", prefix="ghi",
dir="C:/bin/", mode='w',
buffering=-1, delete=False)
print(tp)
tp.close()
同樣在上面的代碼中,這兩個類都期望相同的命名/關鍵字參數在Python> 3中都相同?
這取決於您的平台。 當我閱讀https://github.com/python/cpython/blob/eb126eddbd7542ac9d7cd2736116aee2e0bd03dd/Lib/tempfile.py#L560中的代碼時
if _os.name != 'posix' or _os.sys.platform == 'cygwin':
# On non-POSIX and Cygwin systems, assume that we cannot unlink a file
# while it is open.
TemporaryFile = NamedTemporaryFile
對於非posix(Linux等)環境或cygwin,這些方法相同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.