Home > front end >  'function' object has no attribute 'dumps'
'function' object has no attribute 'dumps'

Time:02-13

I imported pickle from copyreg. I then use the attribute dumps to convert a dictionary into bytes b'\x80\x04...' but it results in the the AttributeError: 'function' object has no attribute 'dumps'

from copyreg import pickle
d={"name":value}
d=pickle.dumps(d)

OUTPUT

AttributeError: 'function' object has no attribute

CodePudding user response:

Your import seems incorrect. It should be:

from pickle import dumps

d = {..}
d = dumps(d)

CodePudding user response:

I imported from the wrong library. The code should have been:

import pickle
d={...}
d=pickle.dumps(d)
  • Related