# Can global variable be passed into Python function?

Ned Batchelder ned at nedbatchelder.com
Sat Mar 1 01:40:06 CET 2014

```On 2/28/14 6:36 PM, Mark H. Harris wrote:
> On Friday, February 28, 2014 3:03:25 PM UTC-6, Marko Rauhamaa wrote:
>>
>> Marko
>
>     ...  and between me and you, here is a snip from dmath.py from the atan(x) function:
>
>      if (n**2 < D(1)):
>          a = __atan__(n)
>      elif (n == D(1)):
>          a = gpi/4
>      elif (n == D(-1)):
>          a = -(gpi/4)
>      elif (n < D(-1)):
>          a = __atan__Lt_neg1__(n)
>      else:
>          a = __atan__Gt_1__(n)
>
>     This if--elif--else  is not only ugly, its just not readable either, and besides that, its not elegant, nor is it humanly helpful...   its does work though, and its absolutely necessary.   ugh.
>
>     First, its not immediately clear what it does. Well, there isn't just one atan(x) routine,  there are at least four of them, depending on whether you're a purist, and they must be selected.
>
>     Second, because of the strict intent ideology of python in the first place, I can't indent this code to make it more readable without breaking python's syntax.
>
>     Third, this is a VERY simple if elif block.  More complex ones are much worse... for human reading that is...
>
>       I know its a pain in the neck, but python does need a switch statement.   Is it a stubborn question?  I don't really think that almost every modern computer language has a switch block because of some C paradigm. I think its because most coders find them useful, at least readable, and therefore essential.

I don't understand: you show an if/elif chain that cannot be expressed
as a switch statement (because it uses < ), and then conclude that
Python needs a switch statement?  That doesn't make any sense.

--
Ned Batchelder, http://nedbatchelder.com

```