受密码保护的 zip 文件无法正确输出?

发布于 2025-01-10 08:58:23 字数 732 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮凉 2025-01-17 08:58:23

输入文件可能位于不同的目录中,因此出现错误。您可以

  1. 设置 inpt = "Groups.txt"
  2. Set 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

  1. Set inpt = "Groups.txt"
  2. Set with open("/Users/name/Desktop/Groups.txt", 'w') as file:
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文