How do you create constants?

Grant Griffin not.this at seebelow.org
Sat Oct 28 11:35:19 EDT 2000


Tom wright wrote:
> 
> Hi All,
> 
> I am a newbie to python, and I have the following question,
> 
> in c++ I can create a constant through something like an enum, or a const
> variable or a static.  How do I go about doing something similar to this in
> python, e.g.
> 
> I want to create a python file/class which contains all my constants for
> ease of use/maintenance.  I then wish to use these from various other
> files/classes.  Now I understand that due to the scoping of python
> variables, I can not simply reference variables in a separate module, but
> how can I achieve something similar to my global defines file as in c++, by
> the way, the defines would be constant strings and integers.
> 
> I am sure there is an easy way to do this, but I havnt found it yet !!

Python _does_ provide constants in two specific ways, strings and
tuples.  The term "immutable sequence" is used to characterize this.  (I
guess "immutable" must be a fancy word for "constant". <wink>).  You can
think of tuples as "constant lists".

However, unlike most other languages, Python doesn't have scalar
constants; if you want those, you'll have to fake them somehow (as
others have suggested.)

if-you-can't-trust-yourself,-who-_can_-you-trust?-<wink>-ly y'rs,

=g2
-- 
_____________________________________________________________________

Grant R. Griffin                                       g2 at dspguru.com
Publisher of dspGuru                           http://www.dspguru.com
Iowegian International Corporation	      http://www.iowegian.com



More information about the Python-list mailing list