欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

Python 标准库 —— zipfile(读取 zip 文件)

发布时间:2025/7/25 python 55 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Python 标准库 —— zipfile(读取 zip 文件) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
  • Python模块学习:zipfile zip文件操作
  • Python 学习入门(16)—— zipfile

0. 解压

with zipfile.ZipFile('../data/jaychou_lyrics.txt.zip', 'r') as zin:zin.extractall('../data/')# 将 .txt.zip 解压为 .txt with open('../data/jaychou_lyrics.txt') as f:f.read()...

1. zipfile 下的 ZipFile 类

f = zipfile.ZipFile(filename) with zipfile.ZipFile(filename) as f:

ZipFile 对象的基本成员函数:

  • f.namelist() ⇒ 由 names 构成的 list;
    • zip 解压出来的文件,当然未必只有一个;
  • f.read(f.namelist()[0])

2. 一个 zip 文件的解析

# 使用 tensorflow 下的相关接口with parse_data(filename):with zipfile.ZipFile(filename) as f:data = tf.compat.as_str(f.read(f.namelist()[0])).split()return data

转载于:https://www.cnblogs.com/mtcnn/p/9421975.html

总结

以上是生活随笔为你收集整理的Python 标准库 —— zipfile(读取 zip 文件)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。