#!/usr/bin/python3.8 # -*- coding:utf-8 -*- # __author__ = 'Qiushi Huang' import optparse # sys.argv的功能类似 # python ftp_client.py -h 192.168.22.33 -p 8091 # user: # password # https://www.cnblogs.com/xiugeng/p/8821302.html # optparse 不再更新,使用 argparse 代替 class FTPClient(object): """ftp客户端""" def __init__(self): usage = "usage: %prog [options] arg1 arg2" parser = optparse.OptionParser(usage) parser.add_option("-s", "--server", dest="server", help="ftp server ip_addr", metavar="SERVER") parser.add_option("-P", "--port", type="int", dest="port", help="ftp server port", metavar="PORT") parser.add_option("-u", "--username", dest="username", help="username info", metavar="USERNAME") parser.add_option("-p", "--password", dest="password", help="password info", metavar="PASSWORD") self.options, self.args = parser.parse_args() if self.args: print('参数不存在,使用testpy.py -h查看帮助') print(self.options, self.args) if __name__ == '__main__': client = FTPClient() # 实例化
标签:__,help,Python,self,parser,optparse,模块,option From: https://www.cnblogs.com/xwupiaomiao/p/17639490.html