python-3.x - 如何修复 Colaboratory 中的 zipfile 读取错误?
问题描述
使用 colaboratory 将 zipfile 提取到我的谷歌驱动器时,我收到一条错误消息,提示 zipfile 读取错误。如何解决?
我正在尝试使用以下 python 3 脚本解压缩文件:
from google.colab import drive
drive.mount('/gdrive')
!unzip '/gdrive/My Drive/file.zip' -d '/gdrive/My Drive/Destination/'
从 zip 中提取 4 个文件后,出现此错误
error: zipfile read error
解决方案
尝试这个:
import zipfile
import os
file_location = 'file_path/file_name.zip'
with zipfile.ZipFile(file_location, 'r') as zip_ref:
zip_ref.extractall('/content') # Replace '/content' with where you want to extract all files.
我希望它不会显示任何错误。
推荐阅读
- javascript - Ajax jQuery 从数据库中获取数据而不刷新
- mysql - 在 SQL 中查询序列有成语吗?
- javascript - 动态表单字段不发送值
- html - 无法在 Razor 页面 [ASP.NET MVC] 上触发控制器事件
- search - 如何在公式中提取交易级别线(NetSuite)
- javascript - 使用多个 URL 创建多个图像
- node.js - 在猫鼬中填充嵌套数组不起作用
- wpf - 更改“IsMouseOver”上“ResourceDirectory”中按钮的样式
- kubernetes - 从 kubernetes .yaml 文件中的 cronjob 创建作业
- c# - 在字典数组中搜索 C#