optparse bug?

Skip Montanaro skip at pobox.com
Fri Jan 2 11:01:48 EST 2004


    Andres> script foo:

    Andres> <def some_function>
    Andres> <define some options with optparse functionality>

    Andres> script bar:

    Andres> from foo import some_function
    Andres> <define options for bar script>

    Andres> When I do ./bar --help I get foo's options!

Perhaps you expect foo to be executed standalone?  If so, wrap the script
init stuff in 

    if __name__ == "__main__":
        <define some options with optparse functionality>

That way you can run it standalone (when you do need optparse) and import it
as a module (when you don't need optparse).

Skip




More information about the Python-list mailing list