mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Correct sys.path[0] when used stand-alone
This commit is contained in:
parent
974e46cc5e
commit
ec577d53a9
1 changed files with 6 additions and 3 deletions
|
@ -496,13 +496,16 @@ def help():
|
||||||
# When invoked as main program, invoke the debugger on a script
|
# When invoked as main program, invoke the debugger on a script
|
||||||
if __name__=='__main__':
|
if __name__=='__main__':
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
if not sys.argv[1:]:
|
if not sys.argv[1:]:
|
||||||
print "usage: pdb.py scriptfile [arg] ..."
|
print "usage: pdb.py scriptfile [arg] ..."
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
# Get the module name and function name, if present
|
filename = sys.argv[1] # Get script filename
|
||||||
filename = sys.argv[1]
|
|
||||||
|
|
||||||
del sys.argv[0]
|
del sys.argv[0] # Hide "pdb.py" from argument list
|
||||||
|
|
||||||
|
# Insert script directory in front of module search path
|
||||||
|
sys.path.insert(0, os.path.dirname(filename))
|
||||||
|
|
||||||
run('execfile(' + `filename` + ')', {'__name__': '__main__'})
|
run('execfile(' + `filename` + ')', {'__name__': '__main__'})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue