11
所以我有一个StringIO()
类似文件的对象,我试图将其写入到一个ZipFile()
,但我得到这个类型错误:如何将Python StringIO()对象传递给ZipFile(),还是不支持?
coercing to Unicode: need string or buffer, cStringIO.StringI found
下面是代码的样本,我使用:
file_like = StringIO()
archive = zipfile.ZipFile(file_like, 'w', zipfile.ZIP_DEFLATED)
# my_file is a StringIO object returned by a remote file storage server.
archive.write(my_file)
该文档说StringIO()
是一个类文件类,并且ZipFile()
可以接受类似文件的对象。有什么我失踪?任何帮助将不胜感激。
在此先感谢!
['ZipFile.write()'](http://docs.python.org/library/zipfile.html#zipfile.ZipFile.write)的参数是一个文件名。 – 2011-06-09 21:52:45
刚发现这个;你的第二行是否有错别字,或者是你的实际代码? 'ZipFile(file_file'而不是'ZipFile(file_like') – Bogdacutu 2011-12-28 15:20:34