每个Python模块都有它的__name__ 属性,如果它是'__main__',这说明这个模块被用户单独运行,我们可以进行相应的恰当操作.
程序代码:
[ 本帖最后由 madfrogme 于 2012-9-2 12:40 编辑 ]
程序代码:#!/usr/bin/python
# Filename: using_name.py
if __name__ == '__main__':
print 'This program is being run by itself'
else:
print 'I am being imported from another module'[ 本帖最后由 madfrogme 于 2012-9-2 12:40 编辑 ]

The quieter you become, the more you can hear






