之前写Python代码,都是随着性子来,想到哪,写到哪,时间长了,发现代码可读性下降,也不利于与其他Pythoner交流。通过阅读一些已有Python模块的代码,归纳出一个程序入口的模板。
纪录下来,备用。
######################我是华丽的分割线-.-###########################
# -*- coding: utf-8 -*-
"""
Name of current .py
xx/xx/20xx
~~~~~~~~
Description of current .py
Copyright
"""
__version__ = ''
__author__ = 'DongXiang <dongxiang1983@gmail.com>'
__url__ = 'http://user.qzone.qq.com/173673927'
__license__ = ''
__docformat__ = 'restructuredtext'
__all__ = []
import sys,getopt
USAGE = """
.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
sys.exit()
except getopt.GetoptError:
print >> sys.stderr, USAGE
return 2
if __name__ == '__main__':
sys.exit(main(sys.argv)) (本文已被浏览 次) | | |