python - Python 脚本无权更改文件
问题描述
在 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)
解决方案
我相信您正在尝试打开具有写入权限的文件,因此您需要使用'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.
推荐阅读
- node.js - 使用 Papaparse 将 JSON 转换为 CSV
- google-apps-script - Gmail 应用程序脚本:回复时执行功能
- node.js - Typeorm:查询以检查多对多关系中是否存在所有值?
- java - 使用 Java 查找按字母顺序排列的第一个字符串
- reactjs - 导航中如何根据 HOC 函数让 react 组件读取或编辑?
- javascript - 如何在 Discord.JS 中通过 ID 踢出 GuildMember?
- python - django.template.loaders.app_directories.Loader 不会在 installed_apps 中搜索模板
- assembly - 在原生 RISC-V 上构建我的汇编程序
- c - bash 直接执行溢出的字符
- c - CRC-16 输出消息检查