constant in python?

Peter Hansen peter at engcorp.com
Sun Aug 19 09:43:27 CEST 2001


[quoting style "corrected" by reordering]

liam wrote:
> "Michael Ströder" <michael at stroeder.com> wrote:
> > Brian Quinlan wrote:
> > > The questions is why do you need explicit language support for
> > > constants? Just don't change the value and it should behave constant
> > > enough for you.
> >
> > To avoid that another developer in the team changes the constant
> > accidently?
>
> agreed, its fine to leave it to yourself to know not to change a constant
> but if its a big project constants would be a nice plus so your associates
> dont mess thing up, accidently?

Two words: "coding standard"

PORT_NAME = 'COM1'
portName = 'COM1'

Only one of these may be changed by my "associates" ... no need for
a "const" keyword (nor even Alex's little gem in most cases) ...

(And, as usual with Python, it still leaves the door open for those
cases where someone _really_ wants to change a so-called constant,
probably during an awkward debugging session, or for a special test
case or something.  _Enforcing_ constancy would prevent that, which
would not be very Pythonic.)

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list