diff options
author | Guido van Rossum <guido@python.org> | 1996-07-30 16:28:13 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-07-30 16:28:13 (GMT) |
commit | f17361d314f118610d6e9ad4ca603350fc986abb (patch) | |
tree | 2201e1e962c0faea67f77e3e199f846b22c76d53 /Lib | |
parent | 81749b0754f0799cb84beedd8b411544a2934c5f (diff) | |
download | cpython-f17361d314f118610d6e9ad4ca603350fc986abb.zip cpython-f17361d314f118610d6e9ad4ca603350fc986abb.tar.gz cpython-f17361d314f118610d6e9ad4ca603350fc986abb.tar.bz2 |
Two changes suggested by Andrew Kuchling:
- move compile() inside try-except
- add code so you can do "python pdb.py <script> <arg> ..." to debug <script>
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/pdb.py | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -1,3 +1,5 @@ +#! /usr/local/bin/python + # pdb.py -- finally, a Python debugger! # (See pdb.doc for documentation.) @@ -74,8 +76,8 @@ class Pdb(bdb.Bdb, cmd.Cmd): locals = self.curframe.f_locals globals = self.curframe.f_globals globals['__privileged__'] = 1 - code = compile(line + '\n', '<stdin>', 'single') try: + code = compile(line + '\n', '<stdin>', 'single') exec code in globals, locals except: if type(sys.exc_type) == type(''): @@ -490,3 +492,17 @@ def help(): else: print 'Sorry, can\'t find the help file "pdb.doc"', print 'along the Python search path' + +# When invoked as main program, invoke the debugger on a script +if __name__=='__main__': + import sys + if not sys.argv[1:]: + print "usage: pdb.py scriptfile [arg] ..." + sys.exit(2) + + # Get the module name and function name, if present + filename = sys.argv[1] + + del sys.argv[0] + + run('execfile(' + `filename` + ')', {'__name__': '__main__'}) |