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

Nick Coghlan ncoghlan at email.com
Mon Oct 4 05:28:06 CEST 2004

Quoting Guido van Rossum <gvanrossum at gmail.com>:
> #!/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).

And is basically identical to the C version of this code (which uses
_PyImp_FindModule and PyRun_SimpleFileExFlags).

I like this idea, as it should automatically work with other versions of the
interpreter like Jython and IronPython, whereas the command line option would
required reimplementation in each interpreter.

The hardest part would be to come up with a name for the script (pymod?,
pymodule?, pyrun?, runpy?).

It will probably be slightly more verbose to invoke than '-m' would be
(particularly on an uninstalled development build), but also easier to enhance
(e.g supporting modules inside packages).

Since I'm on Linux at the moment, and can't recall how the Windows installer
handles things like pydoc, I'll wait and see what Raymond and others think about
how well this would work on Windows.

Unless they think it won't work for other platforms, I'm inclined to reject my
own patch and look at a script-based approach.


Nick Coghlan
Brisbane, Australia

More information about the Python-Dev mailing list