Question about math.pi is mutable
Ben Finney
ben+python at benfinney.id.au
Sat Nov 7 06:35:05 EST 2015
Bartc <bc at freeuk.com> writes:
> On 07/11/2015 03:43, Ben Finney wrote:
> > Bartc <bc at freeuk.com> writes:
> >
> >> Is there no way then in Python to declare:
> >>
> >> pi = 3.141519 # etc
> >>
> >> and make it impossible to override?
> >
> > No, and it would be a bad thing if that were something a library author
> > could forbid.
> >
> > Python assumes the programmers using it are consenting adults. Doing
> > harmful things is difficult but not forbidden.
>
> But surely it can't hurt to ensure certain values can't be changed
> accidentally or maliciously?
The value ‘3.141519’ (in your example above) can't be changed. That
value will always be exactly the same, as long as the program is
running.
What I think you mean is “surely it can't hurt to ensure certain names
can never be bound to any value but their initial binding”.
On that I strongly disagree, for the reasons already discussed in this
thread: it arrogates to the library author the power to forbid patching
the library, which cripples extending, debugging, introspection, and a
host of other useful activities.
--
\ “I object to doing things that computers can do.” —Olin Shivers |
`\ |
_o__) |
Ben Finney
More information about the Python-list
mailing list