一、代码
#!/usr/bin/env python
import sys
from optparse import OptionParser
class RemoteControl:
def run_cmd(self, options):
self.read_file(options.filename)
def read_file(self, filename):
fp = open(filename, "r")
nodes = []
for line in fp.readlines():
nodes.append(line)
fp.close()
print nodes
return nodes
def getopt():
parser = OptionParser()
parser.add_option("-i", "--info", dest = "infomation", help = "info help")
parser.add_option("-f", "--file", dest = "filename", help = "file help")
opt, args = parser.parse_args()
return opt
if __name__ == "__main__":
options = getopt()
if options.infomation:
print options.infomation
rc = RemoteControl()
rc.run_cmd(options)
sys.exit(1)
print "end"
二、运行结果
2.1 文件abc
2.2 运行结果