Python Global Constant
exarkun at twistedmatrix.com
Wed Jul 9 11:21:38 CEST 2003
On Wed, Jul 09, 2003 at 09:49:15AM +0200, Krisztian Kepes wrote:
> Hi !
> I want to create an module and I want to use some Global Constant in it.
> How to I create an global constant in module what is accessable in from other modules ?
Python does not have constant variables. If you remove the "const " on
each of the two lines in your dirs module and use the equality test operator
("==") instead of the assignment operator ("="), your code should work.
As a convention, variables which the author intends not to be changed are
often spelled entirely in capitals, e.g., CONST_DOWN.
> like this example:
> *** module dirs ***
> const Const_Up=1
> const Const_Down=1
> *** module any ***
> import dirs;
> def CheckDir(Dir):
> if Dir=dirs.Const_Up: xxx
"I quite agree with you," said the Duchess; "and the moral of
that is -- Be what you would seem to be' -- or, if you'd like it put
more simply -- Never imagine yourself not to be otherwise than what it
might appear to others that what you were or might have been was not
otherwise than what you had been would have appeared to them to be
otherwise.'" -- Lewis Carrol, "Alice in Wonderland"
More information about the Python-list