title: Launch Python debugger while simultaneously executing module as script
body: <p>When developing a Python package, it's very convenient to use the <code>-m</code> option to run modules inside the package as scripts for quick testing. For example, for <code>somepackage</code> with module <code>somemodule.py</code> inside it, invoking</p>
  
  <pre><code>python -m somepackage.somemodule
  </code></pre>
  
  <p>from the directory where <code>somepackage</code> resides will run <code>somemodule.py</code> as though the submodule were <code>__main__</code>. Using this calling syntax is especially important if the package is using explicit relative imports as described <a href="https://ncoghlan_devs-python-notes.readthedocs.org/en/latest/python_concepts/import_traps.html#the-double-import-trap">here</a>.</p>
  
  <p>Similarly, it is also convenient to use the <code>-m</code> option to debug a script, as in</p>
  
  <pre><code>python -m pdb somescript.py
  </code></pre>
  
  <p>Is there any way to do both at the same time? That is, can I call a module as though it were a script and simultaneously launch into the debugger? I realize I can go into the code itself and insert <code>import pdb; pdb.set_trace()</code> where I want to break, but I'm trying to avoid that.</p>