Constants and Globals
Sean 'Shaleh' Perry
shalehperry at attbi.com
Sat Dec 14 10:30:05 EST 2002
On Saturday 14 December 2002 04:41, Travis Beaty wrote:
>
> 1. Is there such an animal as a "constant" in Python? I've looked
> through the manual, documentation, and FAQ's, but I haven't been able to
> find an answer about that. I'm sure it's there somewhere, and I've just
> overlooked it. I noted that the term "constant" was used, but I am
> unsure whether one can actually lock the value of a variable, or whether
> such constants are simply "constant by agreement."
>
there is no direct support for this in Python. The idiom is to name the
variable in ALL CAPS and never name anything else that way.
> 2. I'm working on an application that needs to have a global variable.
> I, of course, do my best to shy away from globals; however, since this
> is a dictionary which contains user preference settings, I can see no
> other alternative. I've implemented this global variable by placing it
> into a module which will be imported by all other modules. Is this the
> "standard" way that globals are created? Again, I've read the docs and
> tutorial where variable scope is concerned, but I'm still a little
> unclear on it.
>
sounds like the standard approach.
More information about the Python-list
mailing list