[Tutor] Global variables

Kermit Rose kermit at polaris.net
Tue Aug 15 01:33:16 CEST 2006

From: Alan Gauld 
Date: 08/14/06 18:42:41 
To: Kermit Rose; Luke Paireepinart 
Cc: tutor at python.org; Danny Yoo 
Subject: Re: [Tutor] Global variables 
That may be true but you will make your code much less reusable 
and much more error propne in the process. There are good reasons 
why global variables are considered evil... 
I know that global variable usage can be abused.
But in fact I use the same variable names  in the subroutine parameter list
as in the calling routine for every function in the module.
So I believe that in this case global variables would be useful and not
likely to
increase errors due to confusion of global and local variables.
I would never have a local variable with the same name as the global
But in this case, it's only because of an apparent bug in Python that want
bypass that I'm considering the use of global variables.
My routine strongfac calculates a value for fac in the subroutine, and the
calling routine picks up a different vaalue.
An illustration.
In strong fac:
fac = [1,2,3]
print fac
return fac
in fermat:
fac = strongfac(z)
print fac
prints [0,0,0]
And most of the time it does not misbehave like this.
It is only occasionally, and consistently with certain numbers to be
Kermit   <  kermit at polaris.net >

More information about the Tutor mailing list