OT: Re: Just took a look in the perl newsgroup....
Michael Chermside
mcherm at mcherm.com
Wed May 28 08:51:28 EDT 2003
Bengt Richter write:
>> Unfortunately the choice in rebinding inside of the do_something_x's
>> is either local or global, which typically leaves the scope of the
>> above sandwiched in the middle and unmodifiable by reasonable means.
Michael Chermside responds:
>I don't understand what you mean.
>
>Clearly using the first option (the if-elif-else statement) has just
>as much access to variables as a hypothetical case statement would
>have (they're both statements). So I guess (correct me if I'm wrong)
>you're griping only about the approach where one uses a dict of
>functions.
Ben Richter replies with sample code illustrating his point.
Michael Chermside:
Thanks, I think I get it now. What you're saying is that if you
use a dict of functions as a stand-in for a case statement, then
the functions can modify GLOBAL variables, and (of course) variables
local to the functions themselves, but they can't modify nested-scope
variables. So it's as if you can write a case statement, but
within the cases you can't SET any variables (except global
variables or variables that exist only within the case itself).
That's a big limitation. I guess I should probably fall back on
just promoting if-elif-else as the solution for "case" in Python.
-- Michael Chermside
More information about the Python-list
mailing list