I'm using pycharm.2017.1.2.
I installed anaconda2 with py3 environment.
in Pycharm, I'm using Python3 interpreter, and the code is simply:
print(__name__)
In Python console in Pycharm, it prints builtins
.
If I click the 'run' button, it prints main
as expected.
Why does the PyCharm Python console print builtin
instead of main
?
PyCharm Python console is actually running a module called pydevconsole.py
(should be located in C:\Program Files\JetBrains\PyCharm 2017.1.2\helpers\pydev\pydevconsole.py). This module creates an interpreter and sets it as an attribute to the builtins
module.
Thus print(__name__)
on PyCharm console will show builtins
.
During execution (when you click 'run'), your specified Python interpreter is called, not the pydevconsole
module. therefore print(__name__)
shows __main__
as expected.