Can global variable be passed into Python function?

Mark H. Harris harrismh777 at gmail.com
Sat Mar 1 00:30:30 EST 2014


On Friday, February 28, 2014 8:01:45 PM UTC-6, Chris Angelico wrote:


> 
> Does your switch construct have to handle the magic of GT_1 meaning ">
> 1", or do you first figure out where it falls with an if/elif tree?

> ChrisA

hi Chris,   yeah... well think again of the switch block in C...   the switch block selects a branch based on an integral number (int character) that is generally a return code from a function.  The function hides all of that logic. The function runs and returns a "number" which is passed to the switch block. That number generally corresponds to a DEFINE constant at the top or in the header...   so we get something really readable:

x = somefunc()
switch (x):
  case: CONSTANT1
       call blah blah
  case: CONSTANT2
       call blah blah blah
  default
       blah

This very same concept can work in python code too... if everyone would just agree to try. Again, how it switches is less important than does the "switch" appear readable to humans... whether its optimized or not. 

Its up to the devs whether it switches on an int,  a "switch object" whatever I mean by that, or on something else I have not thought about...   the point is ,

    ... can we make something more readable to average people than large if elif else chains, or dict dispatch tables... ??

    Its just a question.   I know Guido thinks not... and a lot of other people too... but what if there is a third option?   If we think about this hard enough there is probably a win win out there that would work/    

just sayin

marcus

  



More information about the Python-list mailing list