optparse global

Skip Montanaro skip at pobox.com
Mon May 16 13:49:24 EDT 2005


    Ashton> How do i make an option passed through command line, using
    Ashton> optparse global. I need to import this value in another file.

Place the parser's output at the module scope.

    global options
    parser = OptionParser()
    parser.add_option("-p", "--port", dest="port", default=5007,
                      type="int",
                      help="port to connect to for remote interpreter")
    ...
    options, args = parser.parse_args()

The user of your module can then execute

    from othermodule import options
    print options.port

Skip



More information about the Python-list mailing list