optparse bug?

Andres Corrada-Emmanuel corrada at dandenong.cs.umass.edu
Fri Jan 2 10:55:01 EST 2004


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_args()

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





More information about the Python-list mailing list