Importing variables non-deterministic?
Antoon Pardon
antoon.pardon at rece.vub.ac.be
Mon Aug 19 13:25:45 EDT 2013
Op 19-08-13 17:04, Chris Angelico schreef:
> On Mon, Aug 19, 2013 at 3:55 PM, Antoon Pardon
> <antoon.pardon at rece.vub.ac.be> wrote:
>> Pity enough they chose a
>> way that didn't allow programmers to protect names they thought
>> important enough to do so too.
>
> As of Python 3, we can redefine something that used to be a keyword,
> which is even stronger than a constant.
>
> def print(*args,print=print,**kw):
> print("##",*args,**kw)
>
> What easier way to tag all your print calls? And this is why it helps
> to have nothing technically constant. You should be able to do the
> same with anything, without having to go and edit someone else's code
> to remove the 'const' keyword.
But what you are showing here is shadowing, not redefintion and you can
do that even if the shadowed name would be a constant.
--
Antoon Pardon
More information about the Python-list
mailing list