简体   繁体   中英

Python change module name to its realname

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__ .

I know this behaviour( if __name__ == '__main__' ), but how can I change the module name back to its real name?

Take a look at module for your module:

print module

Output:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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