之前写Python代码,都是随着性子来,想到哪,写到哪,时间长了,发现代码可读性下降,也不利于与其他Pythoner交流。通过阅读一些已有Python模块的代码,归纳出一个程序入口的模板。纪录下来,备用。 # -*- coding: utf-8 -*- """ Name of current .py xx/xx/20xx ~~~~~~~~ Description of current .py Copyright """ __version__ = '' __author__ = 'A.TNG <jiyucn@163.com>' __url__ = 'http://blog.youkuaiyun.com/jiyucn' __license__ = '' __docformat__ = 'restructuredtext' __all__ = []import sysimport getoptUSAGE = """ .py usage... """ def main(argv): try : opts, args = getopt.gnu_getopt(argv[1:], "h", ["help" ]) for o, a in opts: if o in ("-h", "--help" ): print USAGE except getopt.GetoptError: print >> sys.stderr, USAGE return 2 if __name__ == '__main__' : sys.exit(main(sys.argv))