ethical questions about global variables

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Tue Dec 16 03:45:36 EST 2008


Giampaolo Rodola' a écrit :
> Hi,
> in a module of mine (ftpserver.py) I'd want to add a (boolean) global
> variable named "use_gmt_times" to decide whether the server has to
> return times in GMT or localtime but I'm not sure if it is a good idea
> because of the "ethical" doubts I'm gonna write below.
> 
> In first place I've never liked global variables too much and always
> preferred per-class-instance variables instead.
> The problem in my case is that I have to use such variable in two
> separated classes: FTPHandler and VirtualFileSystem. Also, I want that
> for no reason one class uses times in GMT and the other one local
> times.

Looks like it's more a configuration variable than a global. IOW, it's 
not supposed to change during execution.

> Another doubt is the naming convention. PEP-8 states that global
> variables should use the lower_case_naming_convention but I've seen a
> lot of library module using the UPPER_CASE_NAMING_CONVENTION.

ALL_UPPER_NAMES are pseudo-constants - IOW, they are really variables 
but are by convention considered as constants.

HTH



More information about the Python-list mailing list