Python脚本无权更改文件

时间:2018-08-03 15:54:21

标签: python windows python-3.x permissions

在Windows上运行我的Python加密程序时,某些文件返回一个

File "C:\Users\admin\Desktop\test.py", line 71, in encrypt_file
with open(out_filename, 'wb') as outfile:

PermissionError: [Errno 13] Permission denied:

有没有办法让我的Python程序获得许可?我已经尝试过以管理员身份运行程序以及该网站上的一些特权提升摘要。

代码如下:

with open(in_filename, 'rb') as infile:
        with open(out_filename, 'wb') as outfile:
            outfile.write(struct.pack('<Q', filesize))
            outfile.write(iv)

1 个答案:

答案 0 :(得分:0)

我相信您正在尝试打开具有写访问权限的文件,因此您需要使用'w'

with open(out_filename, 'w') as outfile:

您可以使用特定的参数进行不同的访问,

'w' - Open to write 
'r' -Open to read 
'a' - Open to append at the end of the file.
相关问题