"Don't rebind built-in names*" - it confuses readers

Chris Angelico rosuav at gmail.com
Wed Jun 12 20:08:14 EDT 2013


On Thu, Jun 13, 2013 at 10:04 AM, Mark Janssen
<dreamingforward at gmail.com> wrote:
> Really?
>
>>>> int="five"
>>>> [int(i) for i in ["1","2","3"]]
> TypeError:  str is not callable
>
> Now how are you going to get the original int type back?

Either del it from your module namespace, or use the qualified name:

>>> int="five"
>>> [__builtins__.int(i) for i in ["1","2","3"]]
[1, 2, 3]
>>> del int
>>> [int(i) for i in ["1","2","3"]]
[1, 2, 3]

It's shadowed, not overwritten.

ChrisA



More information about the Python-list mailing list