[wxPython] Case statements in wxPython

I couldn't find any where in the docs re case statements.

I usually program in VB and am transferring a program to python
eg Select case animal
    case "dog"
  do doggy thing here...
   case "Cat"
              etc...
  End select

Does one just have to use the If, elif commands

Precisely. Here is the relevant section from the Python tutorial
(http://www.python.org/doc/current/tut/node6.html):

"An if ... elif ... elif ... sequence is a substitute for the switch or case
statements found in other languages."

···

---
Patrick K. O'Brien
Orbtech.com - Your Source For Python Development Services
Phone: 314-963-3206

-----Original Message-----
From: wxpython-users-admin@lists.wxwindows.org
[mailto:wxpython-users-admin@lists.wxwindows.org]On Behalf Of richard
terry
Sent: Monday, December 17, 2001 6:27 PM
To: wxpython-users@lists.wxwindows.org
Subject: [wxPython] Case statements in wxPython

I couldn't find any where in the docs re case statements.

I usually program in VB and am transferring a program to python
eg Select case animal
    case "dog"
  do doggy thing here...
   case "Cat"
              etc...
  End select

Does one just have to use the If, elif commands

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

richard terry wrote:

I couldn't find any where in the docs re case statements.

I usually program in VB and am transferring a program to python
eg Select case animal
    case "dog"
  do doggy thing here...
   case "Cat"
              etc...
  End select

Does one just have to use the If, elif commands

If you have worker functions do_dog(), do_cat() ... do_else() you can use:

   fx = { 'dog':do_dog, 'cat':do_cat }.get( anumal, do_else )
   fx()

or even better with methods:

    fx = getattr( self, 'do_'+animal, None )
    if callable(fx):
       fx()

HTH
Niki Spahiev