questions about Exceptions?

skanemupp at yahoo.se skanemupp at yahoo.se
Thu Apr 10 06:00:38 EDT 2008


On 10 Apr, 10:51, cokofree... at gmail.com wrote:
> In general you should only catch the exceptions you want to catch,
> therefore avoiding the issue of catching "unexpected" ones, for
> instances the programming unexpectandly closing.
>
> Well, exception handling is expensive (when it catches one) so it
> really is up to you. If you are using eval and know it might "EOF"
> then you should probably look to handle that. The main IF statement
> style I can think of (checking the end of the string) wouldn't be much
> of an improvement.
>
> Currently I would be very worried about seeing that code as it breaks
> a number of "conventions". However it depends on the importance of the
> code to wherever or not you should change this. (Global variable, the
> use of Eval, the CATCH ALL except and the setting of a global variable
> at the end.)
>
> I've seen a good few (simple and advanced) calculator examples using
> python on the NET, it might be worth looking at some to see their
> style of coding a calculator to help your own.


i know about the GLOBAL stuff, i might rewrite the program using
classes later so i can avoid this. i am mainly playin with tkinter for
now.

i was thinking the same check with if at the beginning and end of the
string so there isnt a */ but also if someone uses /// or soemthing
like that in the middle it crashes so it is hard to cover every case,
esp since **5 means ^5.
is the use of if also expensive?



More information about the Python-list mailing list