Fix Python – How to get a reference to a module inside the module itself?

Question

Asked By – Ram Rachum

How can I get a reference to a module from within that module? Also, how can I get a reference to the package containing that module?

Now we will see solution for issue: How to get a reference to a module inside the module itself?


Answer

import sys
current_module = sys.modules[__name__]

This question is answered By – mthurlin

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0