[Patches] [ python-Patches-1035498 ] -m option to run a module as a
script
SourceForge.net
noreply at sourceforge.net
Mon Sep 27 16:22:45 CEST 2004
Patches item #1035498, was opened at 2004-09-28 00:22
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1035498&group_id=5470
Category: Core (C code)
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Nick Coghlan (ncoghlan)
Assigned to: Nobody/Anonymous (nobody)
Summary: -m option to run a module as a script
Initial Comment:
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'.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1035498&group_id=5470
More information about the Patches
mailing list