简体   繁体   English

Python 创建一个包含多个文件的临时目录

[英]Python creating a tempdirectory with multiple files

I am trying to create a temporary directory, where can I write a temporary file (for docker image and.sh scripts), and then I will run docker script to build from that entire directory as image, then remove the temporary directory.我正在尝试创建一个临时目录,我可以在哪里写一个临时文件(用于 docker 图像和 .sh 脚本),然后我将运行 docker 脚本从整个目录构建为图像,然后删除临时目录。 However I can't open the temporary directory to write to:但是我无法打开要写入的临时目录:

temp_dir = tempfile.TemporaryDirectory()
print(temp_dir.name)
with open (temp_dir.name, 'w') as rsh:
    rsh.write('echo test')

I get the error我得到错误

PermissionError: [Errno 13] Permission denied: 'C:\\Users\\j\\AppData\\Local\\Temp\\tmpdwhmvt61'

You can't write data into a directory, try to create a file in your temporary directory.您不能将数据写入目录,请尝试在您的临时目录中创建一个文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM