Reputation: 69
I have a pickle file having many objects. I need to have one proper object by combining all the other objects in the file. How can I do that. I tried using many commands, but none seems to work.
objs = []
while True:
try:
f = open(picklename,"rb")
objs.append(pickle.load(f))
f.close()
except EOFError:
break
Like the one above as shown.
OBJECT stored image :
<nltk.classify.naivebayes.NaiveBayesClassifier object at 0x7fb172819198>
<nltk.classify.naivebayes.NaiveBayesClassifier object at 0x7fb1719ce4a8>
<nltk.classify.naivebayes.NaiveBayesClassifier object at 0x7fb1723caeb8>
<nltk.classify.naivebayes.NaiveBayesClassifier object at 0x7fb172113588>
Upvotes: 1
Views: 139
Reputation: 52153
You should use .extend()
to append all items in the list to objs
:
(Assuming pickle.load(f)
returns a list of objects)
objs.extend(pickle.load(f))
Upvotes: 1