[Fwd: Re: Constants and Globals]

Travis Beaty t.beaty at mchsi.com
Sun Dec 15 09:57:24 EST 2002


Hello again!

Thanks very much for the info!  Since I've had so little experience with 
Python (and programming in general), I will not pretend to be in the 
position to state what is "better."  I've had some negative transfer 
from my C++, which is probably the cause of 90% of my confusion.  But 
... that is a "me" problem, not a Python problem.

Once again, thank you!

Travis Beaty
Mason City, Iowa.

(p.s.  Sorry Mr. Francis for accidentally sending this to you privately.  Oops.)



Erik Max Francis wrote:

>There's really no way to make something _truly_ const without trickery
>(you could, for instance, create an object whose attributes acted as if
>they were constant by preventing you from modifying them, at least if
>they only contained immutable objects).  Python takes the approach of
>"We're all adults here"; instead of trying to enforce things that can be
>hard to enforce in the language (usually there's ways around const
>correctness in other languages, even if they result in undefined
>behavior), Python doesn't even try.
>
>Most of these "hints" are done by convention, rather than by syntax. 
>The common approach to indicate a constant in Python is to have an
>ALL_CAPS_IDENTIFIER (which, of course, isn't specific to Python).
>
>  
>
>>
>>
>Your global could be at the top level of _any_ module, as long as the
>others import it.  Putting it in its own module is a good way to avoid
>hairy issues (one which most Python newbies have come across and been
>confused by), where you have recursive imports.  If the global is in its
>own dedicated module, this definitely lightens the load and eliminates
>the recursive imports problem.
>
>So the short answer is that it may be overkill -- it could really be in
>_any_ module -- but if you have a complex system of modules, it's a good
>way to ensure that you eliminate any kind of import ordering or
>recursing problems.
>
>  
>







More information about the Python-list mailing list