Can global variable be passed into Python function?

Roy Smith roy at
Fri Feb 28 15:43:30 CET 2014

In article <87d2i7wbxs.fsf at>,
 Marko Rauhamaa <marko at> wrote:

> Neil Cerutti <neilc at>:
> > Check out Go's switch statement for an example of what it might
> > look like in Python. Except you'd get it without labeled break or
> > the fallthrough statement.

Python already has a switch statement.  It's just spelled funny...

class Switch(Exception): pass
class Case1(Switch): pass
class Case2(Switch): pass
class Case3(Switch): pass

   raise value
except Case1:
   print "did case 1"
except (Case2, Case3):
   print "did either case 2 or 3"
   print "did default"

No fall-through, however.  I'm sure with a little meta-class magic, you 
could write a Case() which eliminates the need for manually declaring 
the cases.

More information about the Python-list mailing list