开发者

Django. Retrieving and opening a zip file from HDD

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜