我试图格式化文件,以便它可以插入到数据库中,该文件最初是压缩和大约1.3MB大。 每一行看起来是这样的:parse.unquote_plus TypeError
398,%7EAnoniem+001%7E,543,480,7525010,1775,0
这是怎样的代码看起来像这样解析这个文件:
Village = gzip.open(Root+'\\data'+'\\' +str(Newest_Date[0])+'\\' +str(Newest_Date[1])+'\\' +str(Newest_Date[2])\
+'\\'+str(Newest_Date[3])+' village.gz');
Village_Parsed = str
for line in Village:
Village_Parsed = Village_Parsed + urllib.parse.unquote_plus(line);
print(Village.readline());
当我运行程序我得到这个错误:
Village_Parsed = Village_Parsed + urllib.parse.unquote_plus(line);
file "C:\Python31\lib\urllib\parse.py", line 404, in unquote_plus string = string.replace('+', ' ') TypeError: expected an object with the buffer interface
任何想法这里有什么不对? 在此先感谢您的帮助:)
@JFSebastian:你真的尝试过吗?我得到和OP一样的错误...除了他的初始化问题,你的代码看起来在功能上等同于他的返回字节对象。 – 2009-11-04 11:11:08
@John Machin:我试过了(现在)。我找不到'unquote_plus_from_bytes',所以我们不得不求助于显式的'bytes.decode'方法。 – jfs 2009-11-04 11:19:27
谢谢,您的解决方案效果很好,谢谢您指出我的其他错误(Machin和Sebestian)。 我不确定ascii是否是使用过的字符编码,但据我所知,它没有任何问题。 – user202459 2009-11-08 05:40:11