再会,
我对 python 语言非常陌生,我被分配构建一个 python 脚本,该脚本将从电子邮件中获取所有附件文件。附件文件有一个多磁盘部分(.zip、.z01、.z02 等)。使用 zipfile 模块可以轻松提取没有任何多磁盘部分的普通 zip 文件。此代码有效:
password = get_data()
files = [f for f in os.listdir(source_file_name) if isfile(join(source_file_name, f))]
for file in files:
if file.endswith('.zip'):
file_name_split = file.split("_")
resource_name = file_name_split[0]
pswd = password[resource_name]
if resource_name not in listdir('extracted/'):
zip_ref = zipfile.ZipFile('attachments/' +file)
zip_ref.setpassword(pwd = bytes(pswd, 'utf-8'))
zip_ref.extractall('extracted')
zip_ref.close()
os.unlink(source_file_name + file)
但我不能在多磁盘文件中使用该代码,因为 zip 文件模块不支持带有附加注释的 ZIP 文件,或多磁盘 ZIP 文件,如 Zip 文件模块上的文档所述。我在谷歌搜索替代方案,并通过使用 python 子进程模块来使用 7z 应用程序。这是我的代码。
zip_exe = '"C:/Program Files/7-Zip/7z.exe"' + ' x ' '"' + tmp_folder + 'sample.zip' '"'
subprocess.Popen(zip_exe, shell = True, cwd = tmp_extracted_folder)
这在我的本地使用我的桌面 Windows 10 没有任何问题。但我想知道,我怎样才能把这个脚本放在谷歌云功能上?我m not sure that this will work easily by just putting on this script. Do I need to install 7z application on cloud function? I
不确定。你们知道这是否可行吗?我需要帮助,我被这个应用程序卡住了。
如果有其他解决方法,请告诉我。先感谢您。