linux(用python编写命令)
调用optparse模块1.首先编写python程序要在python程序前写#!/usr/bin/env pythonpython解释器运行程序如#!/usr/bin/env pythonfrom optparse import *import osdef main():e="""welcome to :mytest for hello world"""print eif os.geteuid()
·
调用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程序
更多推荐
已为社区贡献1条内容
所有评论(0)