Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 6th, 2005, 9:37 AM   #11
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

Quote:
Originally Posted by bl00dninja
yeah, what they said...

as soon as i saw a bunch of elif's i thought "switch" (a C construct, i guess python calls it something else?) but yeah, a lot of problems have been worked out already and there are a lot of tools to help you focus more on the problem than on copying and pasting. (which is still awesome) :p
Python does not have a "switch" construct, the reason is that even in C "switch" has a poor profile compared to if-else-if and some severe limitations to boot.
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Nov 7th, 2005, 10:03 PM   #12
hydroxide
Programmer
 
Join Date: Apr 2005
Posts: 73
Rep Power: 4 hydroxide is on a distinguished road
Quote:
Originally Posted by Arevos
though I'd have used sys.exit for function number 6, myself. That's probably entirely personal preference, though
It's an artifact of me being on Windows and not needing to return exit vals ;-)Like I said, though, I wouldn't code exactly that way - at a minimum I'd wrap the base level code as a main() function though I'd be more likely to do everything in a class.

Your code has a MAJOR flaw, though
Quote:
Originally Posted by Arevos
    try:
        mytable[get_option()]()
    # If the lookup fails
    except KeyError:
        print "Incorrect value - must use 1 to 6 only."
Bad Bad Bad!! What happens if a bug crops up in one of the functions which triggers a KeyError? If you use lookup tables for functions/methods, always get the function first before calling it (which is why the func() call appears in the else: block, where it will not trap KeyErrors).

--OH.
hydroxide is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:44 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC