Python子进程打开我的Pycharm文件夹和Jupyter文件夹而不是目标

问题描述 投票:0回答:1

您好我试图使用类似于此处详细说明的python子流程解压缩文件夹:4th Solution Down in this thread

我有以下代码:

Z_Location = 'C:\\Program Files (x86)\\7-Zip\\7zFM.exe'
Extract_File ='C:\\Users\\jnardone\\Desktop\\containszips\\myzipfile.zip'
Extract_PW = 'PASSWORD'
Extact_Folder = 'C:\\Users\\jnardone\\Desktop\\containsunzips'

Extract_Target = Z_Location + ' e ' + '"' + Extract_File + '"' + ' -p' + '"' + Extract_PW + '"' + ' -o' + '"' + Extact_Folder + '"'

subprocess.call(Extract_Target)

当我运行此过程时,它只是打开一个7zip窗口,该窗口面向我的Pycharm文件或我的jupyter笔记本文件。见附图:

enter image description here

我相信我的子进程的目标是在某处,我尝试使用os路径,但我不确定语法。

更新:

我已经将子进程更改为在我的计算机目录而不是笔记本/ IDE中工作。但是现在我看到压缩文件的另一个问题没有被解压缩,而是重复。

subprocess.call(r"C:\Program Files (x86)\7-Zip\7z.exe e C:\Users\jnardone\Desktop\folder\file.7z -pPASSWORD",cwd=r'C:\Users\jnardone\Desktop\auto_test_3')

enter image description here

python subprocess unzip 7zip
1个回答
0
投票

解决方案包括以下内容:

  1. 将当前工作目录更改为Pycharm / Jupyter目录。
  2. 将存档目标更改为包含zip文件的主文件夹,而不是直接定位到压缩文件。

希望这可以节省其他人一些时间,因为我很难找到我的问题虽然很简单。

© www.soinside.com 2019 - 2024. All rights reserved.