sys.modules[__name__] - Programmer All
https://www.programmerall.com/article/39731355909tags: my-python sys modules. A way to get a handle to the current running module in Python: import sys. module = sys.modules [__name__] it really only works if you are doing the whole sys.modules litany in the very module you want to get a handle to. Therefore, the meaning of getattr (sys.modules [__ name_____], func_name) is to find an object ...
PEP 499 – python -m foo should bind sys.modules['foo'] in ...
peps.python.org › pep-0499Aug 07, 2015 · When a module is invoked via Python’s -m option the module is bound to sys.modules ['__main__'] and its .__name__ attribute is set to '__main__' . This enables the standard “main program” boilerplate code at the bottom of many modules, such as: if __name__ == '__main__': sys.exit(main(sys.argv)) However, when the above command line invocation is used it is a natural inference to presume that the module is actually imported under its official name module.name , and therefore that if the ...