Python Global Constant

Peter Hansen peter at engcorp.com
Wed Jul 9 05:55:23 EDT 2003


Krisztian Kepes wrote:
> 
> 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 ?
> 
> like this example:
> 
> *** module dirs ***
> const Const_Up=1
> const Const_Down=1

Just do what you did above, without the "const" modifier, which
doesn't exist and is not really needed in Python.

> *** module any ***
> import dirs;
> def CheckDir(Dir):
>   if Dir=dirs.Const_Up: xxx

This code should work fine, although you might want to follow
the Python conventions for capitalization and formatting of
your code, to make it more readable for others.  For example,
variables and functions are generally mixed case, as in checkdir
or dir, while constants are usually ALLCAPS as in CONST_UP.

-Peter




More information about the Python-list mailing list