summaryrefslogtreecommitdiffstats
path: root/Lib/pydoc.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2009-11-15 22:36:47 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2009-11-15 22:36:47 (GMT)
commit11db64e5fd029a2e4db8e9d3c6c4676b410afc72 (patch)
tree4a940aa9c818a2934483c60cf4548d3f45a2fbc6 /Lib/pydoc.py
parentccd5e02d2bc64a48c32c24a1ee988b7dd17a94cf (diff)
downloadcpython-11db64e5fd029a2e4db8e9d3c6c4676b410afc72.zip
cpython-11db64e5fd029a2e4db8e9d3c6c4676b410afc72.tar.gz
cpython-11db64e5fd029a2e4db8e9d3c6c4676b410afc72.tar.bz2
Issue #7328: don't corrupt sys.path when running pydoc with the -m switch
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-xLib/pydoc.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 57071a1..7da75b6 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -2254,11 +2254,13 @@ def cli():
import getopt
class BadUsage: pass
- # Scripts don't get the current directory in their path by default.
- scriptdir = os.path.dirname(sys.argv[0])
- if scriptdir in sys.path:
- sys.path.remove(scriptdir)
- sys.path.insert(0, '.')
+ # Scripts don't get the current directory in their path by default
+ # unless they are run with the '-m' switch
+ if '' not in sys.path:
+ scriptdir = os.path.dirname(sys.argv[0])
+ if scriptdir in sys.path:
+ sys.path.remove(scriptdir)
+ sys.path.insert(0, '.')
try:
opts, args = getopt.getopt(sys.argv[1:], 'gk:p:w')