optparse bug?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andres Corrada-Emmanuel

    optparse bug?

    Hi,

    I'm getting a conflict between options defined between two different
    scripts and I'm wondering if it is a bug or the intended effect.

    script foo:

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

    script bar:

    from foo import some_function
    <define options for bar script>

    When I do ./bar --help I get foo's options! This is fixed by rewriting
    bar.py so the import from foo occurs after parsing bar's options:

    from optparse import OptionParser
    <define options for bar script>
    options, args = parser.parse_ar gs()

    from foo import some_function

    This is mildly annoying behavior. Do I really have to reorder my import
    statements to avoid importing options from other scripts?

    Andres Corrada-Emmanuel
    Senior Research Fellow
    Center for Intelligent Information Retrieval
    University of Massachusetts, Amherst


  • Peter Otten

    #2
    Re: optparse bug?

    Andres Corrada-Emmanuel wrote:
    [color=blue]
    > I'm getting a conflict between options defined between two different
    > scripts and I'm wondering if it is a bug or the intended effect.[/color]

    Neither. I'm pretty sure that you somehow managed to add all options to a
    single OptionParser instance. Do you know about the

    if __name__ == "__main__":
    # code to run only in standalone mode

    technique? For a more detailed analysis you have to provide the actual code
    of a minimal example.

    Peter

    Comment

    Working...