python 动态获当前运行程序的主模块名方法

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

posted @ 2015-01-13 13:55  AndyRobb  阅读(243)  评论(0编辑  收藏  举报