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

Chris Angelico rosuav at gmail.com
Wed Jun 12 20:33:31 EDT 2013


On Thu, Jun 13, 2013 at 10:18 AM, Skip Montanaro <skip at pobox.com> wrote:
> Magic. :-)
>
>>>> int = "five"
>>>> int("a")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: 'str' object is not callable
>>>> from __builtin__ import int as _int
>>>> _int("5")
> 5
>
> Not sure of the magic necessary in Python 3.  This is definitely
> something you don't want to make a habit of...

Same thing works but with a different name:

from builtins import int as _int

ChrisA



More information about the Python-list mailing list