Imported python module overrides option parser

In a previous question, Getting Youtube data using Python

I found that the google api uses argparse.

from outh2client.tools import argparser

My deduction is that it is parsing the sys.argv when imported.

As I asked in the comment, we need to know what errors you are getting. What do mean by 'overrides'? What's the indication of that? Are you getting a parser error message, the kind produced by argparse or optparse? If so, what message.

Show us the commandline that gives the error, along with the error message.

You might want to call the script with -h to see who/what prints parsing help message.


So tools.argparser is an argparse parser with those auth and logging arguments defined. In the question I answered earlier, the user used that parser directly (with an addition of their own). You are using that parser as a parent.

parser = argparse.ArgumentParser(...
        parents=[tools.argparser])                                                                    
flags = parser.parse_args(None)

It now parses sys.argv. Since --user was not defined for this parser, it raises the myscript: error: unrecognized arguments: --user myuser.

One solution is to use:

flags, extras = parser.parse_known_args(None)

Now I expect it to run, and for extras to equal ['--user', 'myuser'].

Another option is to define a --user argument for this parser.

parser.add_argument('-u','--user',help='dummy user argument')