這篇文章將為大家詳細講解有關(guān)python選項參數(shù)的示例分析,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
#!c:python26python.exe
import optparse
def main():
MSG_USAGE = "opt.py [-s
p = optparse.OptionParser(MSG_USAGE)
p.add_option('-s','--server',default="127.0.0.1",help="Server ip your self with this option.")
p.add_option('-p','--port',default="6666",type="int",help="Server port your self with this option.")
p.add_option('-c','--client',default="localhost",help="Client ip your self with this option.")
options, arguments = p.parse_args()
print 'Server: %snPort: %snClient: %s' % (options.server,options.port,options.client)
if __name__ == '__main__':
main()
[@more@]
關(guān)于“python選項參數(shù)的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。