用w打开文件不能写入
>>> city_data = open("city.pkl","wb")>>> pickle.dump("city","city_data")
Traceback (most recent call last):
File "<pyshell#71>", line 1, in <module>
pickle.dump("city","city_data")
TypeError: file must have a 'write' attribute 你的city是啥 dump括号里的city_data不要加冒号,它是个变量,不是字符串 楼上说的对,city_data指向了一个文件对象,然后你将数据写入该文件对象时使用pickle.dump("city", city_data)就可以了,加引号干嘛{:9_241:}
页:
[1]