Python Module getopt usage

Source: Internet
Author: User

1 Importgetopt2 ImportSYS3 defusage ():4     Print 'This is a usage.'5 defMain ():6     Try:7         PrintSYS.ARGV8         #Sys.argv[0], representing the file path, sys.argv[1:], which indicates that the user entered all parameters9         #hp:i, with: Indicates the need for parameters, followed by long parameters need to take ' = 'TenOptions,args = Getopt.getopt (sys.argv[1:],"hp:i:",[" Help","ip=","port="]) One         Print 'Options:', Options A         Print 'args:', args -     exceptgetopt. Getopterror: - sys.exit () the  -     Print '--------------------' -  -      forName,valueinchOptions: +         ifNameinch("- H","--help"): - usage () +     ifNameinch("- I.","--ip"): A         Print 'IP is----', Value at     ifNameinch("- P","--port"): -         Print 'Port is----', Value -  -  - if __name__=="__main__": -Main ()

Python Module getopt usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.