Can global variable be passed into Python function?

Marko Rauhamaa marko at pacujo.net
Fri Feb 28 09:26:23 EST 2014


Neil Cerutti <neilc at norwich.edu>:

> 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.

No need for the fallthrough (except that multiple cases should be
supported).

Labeled breaks wouldn't be needed because there are no fallthroughs.

> Would you still want to use it?

Probably.

Guile (scheme) has:

   (case (state self)
     ((CONNECTING CONNECTED)
      ...)
     ((DISCONNECTING)
      ...)
     (else
      ...))

Python isn't "averse" to the switch statement because it would be not
that useful. Rather, the problem is that Python doesn't have nonliteral
constants (scheme has builtin symbols). It is difficult to come up with
truly Pythonic syntax for the switch statement.

Something like

   switch self.state from Connection.State:
       case CONNECTING or CONNECTED:
           ...
       case DISONNECTING:
           ...
       else:
           ...

would be possible, but here, "Connection.State" is evaluated at compile
time. Don't know if there are any precedents to that kind of thing in
Python.


Marko



More information about the Python-list mailing list