Kobina Adu
Kobina Adu

Reputation: 27

'function' object has no attribute 'dumps'

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 error shown below:

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

Error:

AttributeError: 'function' object has no attribute

Upvotes: 1

Views: 1296

Answers (2)

Jay Patel
Jay Patel

Reputation: 63

Your import seems incorrect. It should be:

from pickle import dumps

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

Upvotes: 2

Kobina Adu
Kobina Adu

Reputation: 27

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

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

Upvotes: 0

Related Questions