[issue37941] python -m and runpy.run_module set different __name__ by default

Nick Coghlan report at bugs.python.org
Wed Sep 11 19:03:31 EDT 2019


Nick Coghlan <ncoghlan at gmail.com> added the comment:

There is one, it just isn't public: runpy._run_module_as_main.

It's a private API that the -m switch implementation calls, and was introduced after the original runpy.run_module was found not to offer everything the switch needed.

It isn't possible to fully emulate -m from Python code though, as the lifecycle of the real main module is intertwined with the lifecycle of the underlying interpreter.

So if folks really want to try to do this, the source code is there to look at, but we're not giving the false impression that it's easy to do correctly with no unintended consequences.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37941>
_______________________________________


More information about the Python-bugs-list mailing list