受密码保护的 zip 文件无法正确输出?
我正在使用 Python 创建组列表。对我来说唯一有意义的是,使用代码,我可以创建受密码保护的 zip,只要在列出输入之前创建输入,我就可以在代码中创建输入。因此,我创建了一个 txt 文件,然后需要将其放入受密码保护的 zip 中。使用下面使用的代码,当我尝试运行它时,我收到此错误消息:(OSError:打开 /Users/name/Desktop/Groups.txt 进行阅读时出错)。我在这方面并不是很有经验,也不知道如何解决这个问题(+我现在非常绝望)。这是我到目前为止的代码,但它不起作用:
#creates .txt file to put in zip folder
with open("Groups.txt", 'w') as file:
file.write("Each row is a group:" + '\n')
for row in final_group:
s = ", ".join(map(str, row))
file.write(s+'\n')
# creates password protected zip
inpt = "/Users/name/Desktop/Groups.txt"
pre = None
oupt = "/Users/name/Desktop/Groups.zip"
password = "password"
com_lvl = 5
pyminizip.compress(inpt, None, oupt, password, com_lvl)
有人可以帮助我吗?
I am using Python to create a list of groups. It only makes sense to me that, using the code, I have for creating the password protected zip, I can create the input in my code as long as it is created before listing the input. As such, I have created a txt file which then needs to be placed in a password protected zip. With the code I am using below, I get this error message when I try to run it: (OSError: error in opening /Users/name/Desktop/Groups.txt for reading). I'm simply not very experienced in this regard and wouldn't know how to solve this issue (+ I am extremely desperate right now). This is the code I have so far, but it does not work:
#creates .txt file to put in zip folder
with open("Groups.txt", 'w') as file:
file.write("Each row is a group:" + '\n')
for row in final_group:
s = ", ".join(map(str, row))
file.write(s+'\n')
# creates password protected zip
inpt = "/Users/name/Desktop/Groups.txt"
pre = None
oupt = "/Users/name/Desktop/Groups.zip"
password = "password"
com_lvl = 5
pyminizip.compress(inpt, None, oupt, password, com_lvl)
Could someone help me out here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
输入文件可能位于不同的目录中,因此出现错误。您可以
inpt = "Groups.txt"
with open("/Users/name/Desktop/Groups.txt", 'w') as file:
The input file might be in a different directory, because of which there's an error. You can either
inpt = "Groups.txt"
with open("/Users/name/Desktop/Groups.txt", 'w') as file: