Constant in python

Tags:

constant in python?

liam wrote:
> “Michael Str?” 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.)

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *