Message46957
Implements the '-m' option recently discussed on
python-dev.
Runs a module 'as if' it had been invoked from the
command line.
E.g., for a build directory, the following two commands
are equivalent:
./python -m pdb
./python Lib/pdb.py
Note that neither of these does the same thing as
"./python -c "import pdb". (In this latter case, any
"if __name__ == "__main__" code would not be executed,
whereas it will be invoked in the first two cases).
Given the vagaries of sys.path, this is quite handy -
if a module can be imported, it can be easily used as a
script too. Not that all modules will necessarily do
anything _interesting_ when used as a script. . .
The current implementation makes changes to main.c
(handle the new argument), pythonrun.[ch] (new flavour
of PyRun_) and import.[ch] (expose a
PyImport_FindModule C API)
Current limitations / to-do if this is pursued:
- print sensible errors for non-Python files (e.g.
hotshot)
- allow 'dotted' names
- decide what to do with packages (e.g. run __init__.py)
- check usage messages in main.c are all still under
512 characters (I assume that limit was set for a reason)
- the 1K limit on absolute file paths seems rather
arbitrary.
- this is code written in the wee hours of the
morning, so it probably has a few other lurking 'features'. |
|
| Date |
User |
Action |
Args |
| 2007-08-23 15:39:56 | admin | link | issue1035498 messages |
| 2007-08-23 15:39:56 | admin | create | |
|