简体   繁体   中英

What is the purpose of “from __builtin__ import True”?

In some python code examples I see, from __builtin__ import True .

True is already built in, so i was wondering why should it be imported?

There's no good reason, unless a module has, for some reason, overridden True , and you want the original value back:

Python 2.7.15 (default, Feb 12 2019, 11:00:12)
>>> True = 8
>>> True
8
>>> from __builtin__ import True
>>> True
True
>>>

Also, True , False and None are keywords in Python 3, so this isn't possible in the first place.

Python 3.7.2 (default, Feb 12 2019, 08:15:36)
>>> True = 8
SyntaxError: can not assign to keyword
>>> from __builtin__ import True
    from __builtin__ import True
SyntaxError: invalid syntax    ^

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM