Trying to save a list of integers in python using pickle, following the exact method given to me by many sources, and I'm still encountering the same error. Here's the simplified version:
import pickle
a=[0,4,8,[3,5]]
with open(blah.pickle, 'wb') as b:
pickle.dump(a,b)
And I always get the error:
NameError: name 'blah' is not defined
What's going wrong?
You need to make it a string:
Without the quotes, Python is looking for the variable called
blah
and trying to get thepickle
attribute of that object. Since you have never definedblah
as a variable, you get aNameError
.You never defined a variable
blah
with apickle
attribute. If you meant the constant string'blah.pickle'
to be the name of the resulting file, put quotes around it, of course...! I.e: