[Tutor] When to use classes
Steven D'Aprano
steve at pearwood.info
Sat Aug 19 20:51:42 EDT 2017
On Sat, Aug 19, 2017 at 10:52:45AM -0500, boB Stepp wrote:
> This thought had occurred to me. Sometimes I wish there was a
> mechanism in Python to create a binding to data where both were
> unchangeable/immutable. Yes, I could use an immutable data type, but
> if I bind an identifier to it that I want to *only* identify that
> data, AFAIK it will always be possible for that identifier to be
> rebound to a different object.
A "constant", in the sense that once bound, it cannot be unbound or
re-bound to another object.
There are some tricky hacks you can use to get something almost like a
constant, e.g.
https://code.activestate.com/recipes/65207-constants-in-python/
but without language support they're probably not worth bothering with.
--
Steve
More information about the Tutor
mailing list