title: python: stop imported module from parsing command line arguments
body: <p>I'm using an external python module, which is not written by me therefore cannot be changed. This module, called magnum (<a href="http://micromagnum.informatik.uni-hamburg.de" rel="nofollow">http://micromagnum.informatik.uni-hamburg.de</a>), processes all optional command line arguments. Here an example to illustrate the behavior:</p>
  
  <p>script1.py</p>
  
  <pre><code>#!/usr/bin/env python
  import magnum
  </code></pre>
  
  <p>executing the script yields:</p>
  
  <pre><code>&gt;&gt;&gt; ./script1.py -h
  [WARNING] - Python Imaging Library not found!
  [WARNING] - -&gt; This means that the ImageShapeCreator and related classes are not available!
  [   INFO] - Imported FFTW wisdom from file
  Usage: scipt1.py [options]
  
  Options:
    --version             show program's version number and exit
    -h, --help            show this help message and exit
  
    Hardware options:
      Options that control which hardware is used.
  
      -g GPU_ID           enable GPU processing (using 32-bit accuracy) on cuda
                      device GPU_ID. The simulator will fall back to CPU
                      mode if it was not compiled with CUDA support or when
                      no CUDA capable graphics cards were detected.
      -G GPU_ID           enable GPU processing (using 64-bit accuracy) on cuda
                      device GPU_ID. TODO: Describe fallback behaviour.
      -t NUM_THREADS, --threads=NUM_THREADS
                      enable CPU multithreading with NUM_THREADS (1..64)
                      threads. This parameter instructs the fftw library to
                      use NUM_THREADS threads for computing FFTs.
  
    Logging options:
      Options related to logging and benchmarking.
  
      -l LEVEL, --loglevel=LEVEL
                      set log level (0:Debug, 1:Info, 2:Warn, 4:Error,
                      5:Critical), default is Debug (0).
      --prof              Log profiling info at program exit.
  
    Parameter sweep options:
      These options have only an effect when the simulation script uses a
      Controller object to sweep through a parameter range.
  
      -p RANGE, --param-range=RANGE
                      select parameter set to run, e.g. --param-range=0,64
                      to run sets 0 to 63.
      --print-num-params  print number of sweep parameters to stdout and exit.
      --print-all-params  print all sweep parameters to stdout and exit.
  
    Miscellanous options:
      --on_io_error=MODE  Specifies what to do when an i/o error occurs when
                      writing an .omf/.vtk file. 0: Abort (default), 1:
                      Retry a few times, then abort, 2: Retry a few times,
                      then pause and ask for user intervention
  </code></pre>
  
  <p>Now I want to write a small script that takes its own command line arguments and then uses the magnum module to perform some small calculation. I would like to use argparse to parse the arguments. However, argparse seems to have a lower priority than the argument processing of this external module and my own arguments fail to be recognized:</p>
  
  <p>script2.py</p>
  
  <pre><code>#!/usr/bin/env python
  import argparse
  import magnum
  parser = argparse.ArgumentParser(
          description='TEST')
  parser.add_argument('--x',
          help='test_arg')
  args = parser.parse_args()
  print args.x
  </code></pre>
  
  <p>Calling it:</p>
  
  <pre><code>&gt;&gt;&gt;./scrip2.py --x 3
  [WARNING] - Python Imaging Library not found!
  [WARNING] - -&gt; This means that the ImageShapeCreator and related classes are not available!
  [   INFO] - Imported FFTW wisdom from file
  Usage: test.py [options]
  
  test.py: error: no such option: --x
  </code></pre>
  
  <p>It does not matter if I import argparse before or after magnum. The argparse works if I don'f import magnum:</p>
  
  <p>script3.py</p>
  
  <pre><code>#!/usr/bin/env python
  import argparse
  parser = argparse.ArgumentParser(
          description='TEST')
  parser.add_argument('--x',
          help='test_arg')
  args = parser.parse_args()
  print args.x
  </code></pre>
  
  <p>Executing it yields:</p>
  
  <pre><code>&gt;&gt;&gt;./scrip2.py --x 3
  3
  </code></pre>
  
  <p>My question is: How can I stop magnum from processing my command line arguments, without editing magnum?</p>