optparse bug?

  • Thread starter Andres Corrada-Emmanuel
  • Start date
A

Andres Corrada-Emmanuel

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
 
P

Peter Otten

Andres said:
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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top