Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
win 7 中的 temp 目录是%userprofile%\AppData\Local\Temp,我想将它作为变量添加到 python 脚本中,用于在那里创建文本文件。
%userprofile%\AppData\Local\Temp
但是,由于%开头的原因,导致python无法识别。我尝试添加 double %%,但效果不佳。
%
%%
我应该怎么办?
您应该改用该tempfile模块:
tempfile
import tempfile my_temp = tempfile.NamedTemporaryFile()
这是拥有临时文件的独立于平台的方式。