static variables

Steven D'Aprano steve at pearwood.info
Wed Dec 2 08:17:16 EST 2015


On Wed, 2 Dec 2015 10:30 pm, Marko Rauhamaa wrote:

> Antoon Pardon <antoon.pardon at rece.vub.ac.be>:
> 
>> Op 02-12-15 om 11:18 schreef Marko Rauhamaa:
>>> I don't know why global accessibility is such a problem.
>>
>> Some people seem to have a problem with global variables.
> 
> Well, *I* don't go around defining global variables, but there are times
> when they are the way to go. For example, if a module function uses a
> regular expression, the regular expression should be compiled into a
> (module) global variable.
> 
> Module functions and classes are global variables as well:

Actually, those examples are more usually global *constants* (or at least
the closest thing that Python has to constants). While we can rebind
math.sqrt, as in your example, treating it as a variable, we normally would
not do so. We would normally treat such module level objects as constants.



-- 
Steven




More information about the Python-list mailing list