'-m' option (was RE: [Python-Dev] ConfigParser patches) (original) (raw)

Guido van Rossum gvanrossum at gmail.com
Sun Oct 3 06:33:09 CEST 2004


Correct. Ilya's original example was wanting to invoke pdb's script behaviour in order to debug another script. At the moment, you have to run:

python -c "from inspect import getsourcefile; import pdb; print getsourcefile(pdb)" or python -c "from imp import findmodule; print findmodule("pdb")[1]" to find out where the file is, and then run python normally with the filename that gets printed by one of the above scripts. (With a Unix-style shell, backticks make that easier. Doesn't help on Windows though). The "-m" option aims to automate this process (using the latter 'findmodule' approach in C code)

I'm not going to stop you from adding this, but I do think you're overlooking the fact that if you need this a lot, it's trivial to write a tiny Python script that takes the place of "python -m", and putting that python script in your PATH. Something like:

#!/usr/bin/env python import sys, imp fn = imp.find_module(sys.argv[1])[1] del sys.argv[0] sys.argv[0] = fn execfile(fn)

seems do the trick (though it could use nicer error handling).

Wouldn't it be easier to add this to the Tools/scripts directory (and the list of scripts that are installed by "make install" or the Windows equivalent) than to burden the Python interpreter with C code to do the same? Why does every handy thing that anyone ever thought of have to be a Python command line option?

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list