开发者

Django. Retrieving and opening a zip file from HDD

开发者 https://www.devze.com 2022-12-20 19:39 出处:网络
I have a path to a zip file. I don\'开发者_StackOverflow社区t know how to retrieve the file from the hard drive

I have a path to a zip file. I don'开发者_StackOverflow社区t know how to

  • retrieve the file from the hard drive or
  • open that zip file. Does anyone know?

The zip file is a zip file, but it's really a .epub file.


http://docs.python.org/library/zipfile.html

>>> import zipfile
>>> path = "example/path.epub"
>>> epub = zipfile.ZipFile(open(path))
>>> epub.namelist()
 ['some_file.txt']
>>> file = epub.open('some_file.txt')
>>> file.read()


You don't need anything Django specific, just use the Python standard library, with the class ZipFile(file_name[, mode[, compression[, allowZip64]]]) from the zipfile package.

0

精彩评论

暂无评论...
验证码 换一张
取 消