If I wanted to get the current module, e.g. to reload it, I would do:
import sys sys.modules[__name__] Is there a better way to do this (e.g. not involving __name__)? Better in this context means more idiomatic, more portable, more robust, or more...any of the other things we usually desire in our software.
I use python 2, but answers for python 3 will no doubt be useful to others.
sys.modules[__name__]is exactly right.__name__, and explains why there are no better alternatives that can avoid any of them in Python as it is today (3.4—and of course it's even more true for 2.7). (Despite the title, it proposed a few related changes, not just adding__qualname__, like a special metapath hook to make__main__and the real module name act equivalent.)