Python OptionParser module, pythonoptionparser

Source: Internet
Author: User

Python OptionParser module, pythonoptionparser

OptionParser is a module used in python to process command lines. It is a necessary tool for process-based development using python.

Optparse, Which is powerful and easy to use, allows you to easily generate standard, Unix/Posix-compliant command line instructions

Case code

From optparse import OptionParserparse = OptionParser () parse. add_option ("-l", "-- language", action = "store_true", dest = "lan", default = True, help = "write language for Program") (option, arges) = parse. parse_args () if option. lan = True: print 'lan is true'

As shown above, first import the OptionParser class to create the OptionParser object

Use add_option () to define the command line parameters, and finally use parse_args () to parse the command line

Add_option Parameter Parsing. action contains store (default), store_false, store_false, store_const, append, count, and callback.

Another function of OptParser is to automatically generate program help information. For more information, see the previous study.

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.