def main_module_name(): mod = sys.modules['__main__'] file = getattr(mod, '__file__', None) return file and os.path.splitext(os.path.basename(file))[0]