调用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程序