首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

pyhthon zipfile获取压缩文件列表后怎样打开其中某个文件?该如何处理

2012-02-13 
pyhthon zipfile获取压缩文件列表后怎样打开其中某个文件?如题。似乎ZipFile没有open操作..zCmfile zipfi

pyhthon zipfile获取压缩文件列表后怎样打开其中某个文件?
如题。似乎ZipFile没有open操作..


zCmfile = zipfile.ZipFile(targetPath,'r')
  for oneFile in zCmfile.namelist():
  if oneFile[:-4] == omcName:
  print oneFile
  #以append方式打开需要写入的文件

[解决办法]
ZipFile.open(name[, mode[, pwd]]) 
Extract a member from the archive as a file-like object (ZipExtFile). name is the name of the file in the archive, or a ZipInfo object. The mode parameter, if included, must be one of the following: 'r' (the default), 'U', or 'rU'. Choosing 'U' or 'rU' will enable universal newline support in the read-only object. pwd is the password used for encrypted files. Calling open() on a closed ZipFile will raise a RuntimeError.

只读而已,如果你要改写嘛要整个解压,修改,再压缩比较费事,或者删掉原来的entry再附加新文件,貌似内建模块还没有实现直接更新的方法...

热点排行