简体   繁体   English

Python将模块名称更改为其真实名称

[英]Python change module name to its realname

app.py : app.py

import sys

for name, module in sys.modules.iteritems():
    print name

I get: 我得到:

encodings
site
__builtin__
sysconfig
__main__
....

as you can see, the module name is changed to __main__ . 如您所见,模块名称更改为__main__

I know this behaviour( if __name__ == '__main__' ), but how can I change the module name back to its real name? 我知道这种行为( if __name__ == '__main__' ),但是如何将模块名称改回其真实名称?

Take a look at module for your module: 看看module为模块:

print module

Output: 输出:

<module '__main__' from 'app.py'>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM