You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'__console__' instead of '__main__' as __name__ in bpython 0.20.1 #868
(py3) DC@bdd14:~/code/stable$ bpython
bpython version 0.20.1 on top of Python 3.8.5 /home/.../miniconda3/envs/py3/bin/python
>>> __name__
'__main__'
but this doesn't:
(py3) DC@bdd14:~/code/stable$ bpython -i main.py
bpython version 0.20.1 on top of Python 3.8.5 /home/.../miniconda3/envs/py3/bin/python
>>> __name__
'__console__'
@sebastinas After a brief debugging, I found out that the __name__ is getting changed to __console__ in __main__.py.
And as we are importing the main, it gives __console__.
Sorry if this sounds obvious/rubbish as I am not a pro, but if you could direct me towards something, I would like to help.
Edit: Little more digging and I think this is because of a Helper to execute code in a given interpreter in args.py as we are loading specs from __console__. Looks like expected behaviour.
__name__ is set to __console__ by code.InteractiveInterpreterby default. I don't remeber if there was a specific reasons to keep this behavior. I think that we should align bpython's behavior with that of python.
Activity
vmdhhh commentedon Dec 22, 2020
@sebastinas After a brief debugging, I found out that the
__name__is getting changed to__console__in__main__.py.And as we are importing the
main, it gives__console__.Sorry if this sounds obvious/rubbish as I am not a pro, but if you could direct me towards something, I would like to help.
Edit: Little more digging and I think this is because of a Helper to execute code in a given interpreter in
args.pyas we are loading specs from__console__. Looks like expected behaviour.sebastinas commentedon Dec 31, 2020
The behavior should be consistent with the vanilla Python interpreter. Whatever it does, should be emulated here.
vmdhhh commentedon Jan 1, 2021
@sebastinas Does this mean that the
__name__should output__main__everywhere?colomb8 commentedon Jan 2, 2021
no, only in the main script, while in the others should return the name of each module
sebastinas commentedon Jan 8, 2021
pythonhas the following behavior:__name__is set to__console__bycode.InteractiveInterpreterby default. I don't remeber if there was a specific reasons to keep this behavior. I think that we should alignbpython's behavior with that ofpython.Set up __main__ module (fixes #959, #868)
sebastinas commentedon May 2, 2022
Fixed in 14669c0.