似乎遇到了一个新手错误,但我不是新手。
我有一个大小为1.2G的压缩文件'train.zip',其中包含一个3.5G的'train.csv'文件。
我打开了压缩文件和文件本身,没有出现任何异常(没有LargeZipFile),但结果文件流似乎为空。(UNIX 'unzip -c ...' 确认它是好的)
Python
ZipFile.open()
返回的文件对象不能被定位或告知,所以我无法检查它们。
Python分发版是2.7.3 EPD-free 7.3-1 (32-bit);但应该适用于大型压缩文件。操作系统是MacOS 10.6.6。import csv
import zipfile as zf
zip_pathname = os.path.join('/my/data/path/.../', 'train.zip')
#with zf.ZipFile(zip_pathname).open('train.csv') as z:
z = zf.ZipFile(zip_pathname, 'r', zf.ZIP_DEFLATED, allowZip64=True) # I tried all permutations
z.debug = 1
z.testzip() # zipfile integrity is ok
z1 = z.open('train.csv', 'r') # our file keeps coming up empty?
# Check the info to confirm z1 is indeed a valid 3.5Gb file...
z1i = z.getinfo(file_name)
for att in ('filename', 'file_size', 'compress_size', 'compress_type', 'date_time', 'CRC', 'comment'):
print '%s:\t' % att, getattr(z1i,att)
# ... and it looks ok. compress_type = 9 ok?
#filename: train.csv
#file_size: 3729150126
#compress_size: 1284613649
#compress_type: 9
#date_time: (2012, 8, 20, 15, 30, 4)
#CRC: 1679210291
# All attempts to read z1 come up empty?!
# z1.readline() gives ''
# z1.readlines() gives []
# z1.read() takes ~60sec but also returns '' ?
# code I would want to run is:
reader = csv.reader(z1)
header = reader.next()
return reader
try..catch
来处理它。EAFP哲学。 - smci