我的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
网友评论