module 'pickle' has no attribute 'dump'

孤街浪徒 提交于 2020-06-25 01:42:14

问题


import pickle

imelda = ('More Mayhem',
          'IMelda May',
          '2011',
          ((1, 'Pulling the Rug'),
           (2, 'Psycho'),
           (3, 'Mayhem'),
           (4, 'Kentish Town Waltz')))

with open("imelda.pickle", "wb") as pickle_file:
    pickle.dump(imelda, pickle_file)

I am trying to execute this code, but the console keeps telling me:

module 'pickle' has no attribute 'dump'

Do I have to install pickle via pip? I am not sure what is happening here.


回答1:


Happened to me too. I had a file called pickle.py in my current directory. Just rename it and it's fixed :)




回答2:


You might have used your Python file name as pickle.py. Python interpreter is confused and looking for dump function in you file pickle.py instead of the package you have imported. Change the name of your file to something else, it will work.



来源:https://stackoverflow.com/questions/48087036/module-pickle-has-no-attribute-dump

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!