Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a61f4ac

Browse files
author
Just van Rossum
committed
better sys.path munging when running scripts -- jvr
1 parent 98be47e commit a61f4ac

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

Mac/Tools/IDE/PyEdit.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,7 @@ def execstring(self, pytext, globals, locals, file, modname):
501501
dir = os.path.dirname(self.path)
502502
savedir = os.getcwd()
503503
os.chdir(dir)
504-
try:
505-
cwdindex = sys.path.index(os.curdir)
506-
except ValueError:
507-
cwdindex = None
508-
else:
509-
sys.path[cwdindex] = dir
504+
sys.path.insert(0, dir)
510505
else:
511506
cwdindex = None
512507
try:
@@ -515,8 +510,7 @@ def execstring(self, pytext, globals, locals, file, modname):
515510
finally:
516511
if self.path:
517512
os.chdir(savedir)
518-
if cwdindex is not None:
519-
sys.path[cwdindex] = os.curdir
513+
del sys.path[0]
520514

521515
def getenvironment(self):
522516
if self.path:

0 commit comments

Comments
 (0)