[Tutor] Little pickle playing up on me (original) (raw)
adam adam at monkeez.org
Fri Jul 9 11:36:10 CEST 2004
- Previous message: [Tutor] switch statements
- Next message: [Tutor] Little pickle playing up on me
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I've got two functions (see below) which load pickled objects in to memory
- one (loadcollection) which worked by querying the user for a string to provide a file name and unpickling it. The second function (load_existing_function) takes a command line argument, which has been tested for and turned into a string.
I'm getting the error:
Traceback (most recent call last): File "D:\cygwin\home\rdgac2\cvs\newmag\newmag.py", line 505, in ? mainmenu() # Kicks the whole thing off File "D:\cygwin\home\rdgac2\cvs\newmag\newmag.py", line 468, in mainmenu load_existing_collection(filepassed) File "D:\cygwin\home\rdgac2\cvs\newmag\newmag.py", line 450, in load_existing_collection instance = pickle.load(openfile) File "C:\Python23\lib\pickle.py", line 1390, in load return Unpickler(file).load() File "C:\Python23\lib\pickle.py", line 872, in load dispatchkey KeyError: '#'
Any ideas?
Thanks adam
429 def loadcollection(): 430 """This function will load a file which is a cpickled object of a- 431 magazine collection.- 432 """ 433 filename = raw_input("What is the filename?") 434 try: 435 436 file = open (filename, 'r') 437 except IOError: 438 print "That file was not found!"- 439 loadcollection() 440 instance = pickle.load(file) 441 #instance.collectionmenu() This used to take you to the instances menu 442 # but now we are going to a new edit/search menu-- 443 edit_or_search(instance) 444 445 def load_existing_collection(file): 446 >---print type (file) 447 >---print file 448 >---try: 449 >--->---openfile = open(file, 'r') 450 >--->---instance = pickle.load(openfile) 451 >--->---edit_or_search(instance) 452 >---except IOError: 453 >--->---print "That file doesn't exist, please try again" 454 >--->---loadcollection() 455 >---#instance = pickle.load(openfile) 456 >---#edit_or_search(instance)
459 def mainmenu(): 460 >---"""This method is the main entry point method that the user will first see. 461 >---It asks them whether they want to create a new collection, or load- 462 >---an existing one 463 >---""" 464 465 >---if sys.argv: 466 >--->---filepassed = str(sys.argv[0]) 467 >--- 468 >--->---load_existing_collection(filepassed) 469 470 >---else: 471 >--->---print ''' 472 >--->---################################### 473 >--->---# Main Menu # 474 >--->---################################### 475 476 477 >--->---What would you like to do?- ... ...
- Previous message: [Tutor] switch statements
- Next message: [Tutor] Little pickle playing up on me
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]