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!

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'}

Thank you!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.