472,119 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

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_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
Jul 18 '05 #1
1 1382
Andres Corrada-Emmanuel wrote:
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

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Hans-Joachim Widmaier | last post: by
7 posts views Thread by Henry Ludemann | last post: by
5 posts views Thread by Norbert Thek | last post: by
3 posts views Thread by Karlo Lozovina | last post: by
3 posts views Thread by Bob | last post: by
reply views Thread by Steven Bethard | last post: by
reply views Thread by Robert Kern | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.