0

Please give me ideas why would I get following errors:

Traceback (most recent call last):
  File "C:\temp_Jag\FilePickling.py", line 3, in <module>
    unpickledlist = pickle.load(unpicklefile)
  File "C:\Python26\lib\pickle.py", line 1370, in load
    return Unpickler(file).load()
  File "C:\Python26\lib\pickle.py", line 858, in load
    dispatch[key](self)
  File "C:\Python26\lib\pickle.py", line 1142, in load_pop_mark
    k = self.marker()
  File "C:\Python26\lib\pickle.py", line 874, in marker
    while stack[k] is not mark: k = k-1
IndexError: list index out of range

..for the following code:

import pickle
unpicklefile = open('Ex.txt', 'rb')
unpickledlist = pickle.load(unpicklefile)
unpicklefile.close()

Thank you!

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Irina77
2

You cannot just open an ordinary txt file with pickle.
You have to dump something to it first.

# Save a dictionary into a pickle file.
import pickle

favorite_color = {"lion": "yellow", "kitty": "red"}
pickle.dump(favorite_color, open("Ex.txt", "wb"))

favorite_color = pickle.load(open("Ex.txt", "rb" ))
print(favorite_color) #{'lion': 'yellow', 'kitty': 'red'}

Edited by snippsat: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.