如何腌一个对象? [英] How do I pickle an object?
本文介绍了如何腌一个对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
import pickle
/ pre>
alist = ['here ,'there']
c = open('config.pck','w')
pickle.dump(alist,c)
这是我收到的错误:
追溯(最近的电话最后):
文件C:\pickle.py,第1行,在?
import pickle
文件C:\pickle.py,第6行,?
pickle.dump(alist,c)
AttributeError:'module'对象没有属性'dump'
发生了什么?我在windows xp上使用python 2.4
解决方案不要调用你的文件pickle.py。它与同名的python标准库模块冲突。所以你的
import pickle
没有拿起python模块。Here is the code I have:
import pickle alist = ['here', 'there'] c = open('config.pck', 'w') pickle.dump(alist, c)
and this is the error I receive:
Traceback (most recent call last): File "C:\pickle.py", line 1, in ? import pickle File "C:\pickle.py", line 6, in ? pickle.dump(alist, c) AttributeError: 'module' object has no attribute 'dump'
whats going on? I am using python 2.4 on windows xp
解决方案Don't call your file pickle.py. It conflicts with the python standard libary module of the same name. So your
import pickle
is not picking up the python module.这篇关于如何腌一个对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文