eval() woes

rdrink rdrink at gmail.com
Tue Aug 29 14:19:47 EDT 2006


Thanks everyone for you thoughtful replies...

And yes Simon you are right... I do need to learn how to read
'tracebacks' (and de-bugging tools in general)... but you are the first
person to give me a step-by-step explination, thank you.

And LOL you all caught my dropped single-quote ;-) ....
but unfortunately that was just a typo, not generated by my code.

And Simon thanks for this....

> That's a lot of calls to str() to change the parts of parts *back* into
> strings after changing them into ints.  Why don't you just say
> something like:
>
> soL, siL, siR, soR = parts
> oL, iL, iR, oR = map(int, parts)
> oLoL =  int(soL + soL)
> oLiL =  int(soL + siL)
> .
> .
> .
> etc...
> ?

... I've never used mapping before, so this will be a good start.

> If you're calling this function as many times as you indicate below
> (just under a quarter of a million(!) if I understand you correctly,
> 480*500 = 240,000) , it might even result in a human-noticeable speed
> up.  ;-)

Oh it get's worse that that... it'll be (possibly) up to 500 times per
equation, for 334 equations, for 480 'seed numbers'... 500 * 334 * 480
= 80,327,000 calculations =:-o
So every little speed up helps!

----
> Ok, so there you go.  At this point in the program parts[1] is '-',
> which isn't an int literal, so the script raises an exception.  One
> very good thing to do here, as others have already mentioned, would be
> to "print parts" at the beginning of your equate() function.  That way
> you could see exactly which data are causing the problem.

Ok guys I'm not such a noob I didn't try that ;-)
but unfortunately it didn't enlighten anything.
However, as Simon points out...

> None of this has anything to do with the error you posted.  You're not
> even getting as far as calling eval() or pow().
> The traceback tells you, unambiguously, that it's the latter, the
> variable cast.

the one thing I didn't mention (in trying to spare everyone having to
read *all* my code) is that the above mentioned list 'parts' of which I
am trying to use parts[1] etc, is passed in from another function...
and though I have gone over it repaetedly, looking for possible sources
of errors, Simons suggestion points to the problem originating there...
so I'll just have to keep looking.

Unfortunately I am going to have to put this project* away for a while
now, so let me just thank everyone again for helping a newcomer (I hope
someday I can return the favor) and let's retire this thread.

* BTW If any of you are interested in details of the project it's self
feel free to email me.

Thanks again!




More information about the Python-list mailing list