Simon and all,

What would you recommend? I don't know what I should code, because I haven't
coded anything that loads a file. 

Thanks,
Nathan Pinno
MSN Messenger: [EMAIL PROTECTED]
Yahoo! Messenger: spam_swatter31
AIM: f3mighty
ICQ: 199020705  

-----Original Message-----
From: Simon Gerber [mailto:[EMAIL PROTECTED] 
Sent: December 20, 2005 3:38 PM
To: Nathan Pinno
Cc: tutor@python.org
Subject: Re: [Tutor] How do I fix this IndexError?

Hi Nathan,

> Traceback (most recent call last):
>   File "D:\Python24\exchange.py", line 28, in -toplevel-
>     exch = pickle.load(store)
>   File "D:\Python24\lib\pickle.py", line 1390, in load
>     return Unpickler(file).load()
>   File "D:\Python24\lib\pickle.py", line 872, in load
>     dispatch[key](self)
>   File "D:\Python24\lib\pickle.py", line 1207, in load_appends
>     mark = self.marker()
>   File "D:\Python24\lib\pickle.py", line 888, in marker
>     while stack[k] is not mark: k = k-1
> IndexError: list index out of range

As you can see from the traceback, the error is occuring entirely in the
pickle module. Which probably means your pickle file is corrupted.
Or that you're trying to load your old exch.txt file which wasn't in pickle
format.

Simply delete 'exch.txt' and try again. Although you'll notice your program
still doesn't work, because it tries to load 'exch.txt' even if there isn't
an exch.txt.

You should consider rewriting your program so that it checks to see if an
'exch.txt' file exists. If it does, it unpickles it. If not, it uses your
default 'rates' variables.

Speaking of rates, you have two typos in your code which you also need to
fix.

> exch = pickle.load(store)

Should be

rates = pick.load(store)

And similarly,

>         pickle.dump(exch, store)

pickle.dump(rates, store)

Otherwise you're not saving or loading anyhing!

Cheers,

--
Seen in the release notes for ACPI-support 0.34:

'The "I do not wish to discuss it" release
  * Add workaround for prodding fans back into life on resume
  * Add sick evil code for doing sick evil things to sick evil
    screensavers'
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to