美文网首页
Python简单脚本模版

Python简单脚本模版

作者: freelamb | 来源:发表于2017-09-05 15:14 被阅读57次

    我的python模版

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    
    import sys
    
    
    # parse main argv
    def parse_argv():
        for index in range(1, len(sys.argv)):
            argv = sys.argv[index]
            print argv
    
    
    # write data to file
    def write_file(file_path, data):
        file_desc = open(file_path, "aw")
        file_desc.write(data)
        file_desc.close()
    
    
    # main
    def main():
        print "hello world!"
    
    
    # start
    if __name__ == "__main__":
        parse_argv()
        write_file("./aaa.log", "ddd")
        main()
    

    python之父的模版

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    
    import sys
    import getopt
    
    class Usage(Exception):
        def __init__(self, msg):
            self.msg = msg
    
    def main(argv=None):
        if argv is None:
            argv = sys.argv
        try:
            try:
                opts, args = getopt.getopt(argv[1:], "h", ["help"])
            except getopt.error, msg:
                raise Usage(msg)
            # more code, unchanged
        except Usage, err:
            print >>sys.stderr, err.msg
            print >>sys.stderr, "for help use --help"
            return 2
    
    if __name__ == "__main__":
        sys.exit(main())
    
    python

    相关文章

      网友评论

          本文标题:Python简单脚本模版

          本文链接:https://www.haomeiwen.com/subject/jxgujxtx.html