调用optparse模块

1.首先编写python程序

要在python程序前写
#!/usr/bin/env python
python解释器运行程序

#!/usr/bin/env python
from optparse import *
import os
def main():
	e="""welcome to :
	mytest for hello world"""
	print e
	if os.geteuid()!= 0:
		print("Running without root privilages.")
	usage=""" Usage:  [--show display something]"""
	Parser = OptionParser(usage=usage)
	Parser.add_option("-s", "--show", dest="message", action="store", help="display something", default="hello world")
	(options,args)= Parser.parse_args()
	if options.message:
		print(options.message)
if __name__ == "__main__":
    main()

添加python链接到/user/bin目录

sudo ln -s `pwd`/test.py /usr/bin/helloworld
sudo chmod +x /usr/bin/helloworld

之后用helloworld调用python程序

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐