[Idle-dev] IDLEfork 0.9a2 - Duplicate items in sys.path
David Harris
dpharris76@msn.com
Sun, 2 Mar 2003 14:24:13 -0600
This is a multi-part message in MIME format.
------=_NextPart_000_0005_01C2E0C7.65FE6600
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
When main() expands the current directory element (" ") of sys.path, a =
duplicate item will be added to sys.path if the current directory is a =
member of sys.path. For example, if my current directory is =
"C:\\Python22\\Scripts", I end up with two instances for this directory. =
That is: ['C:\\Python22\\Scripts', 'C:\\Python22\\Scripts', =
'C:\\PYTHON22\\DLLs', 'C:\\PYTHON22\\lib', 'C:\\PYTHON22\\lib\\lib-tk', =
'C:\\PYTHON22', 'C:\\PYTHON22\\lib\\site-packages']
The duplicate(s) can be eliminated by changing:
# process sys.argv and sys.path:
for i in range(len(sys.path)):
sys.path[i] =3D os.path.abspath(sys.path[i])
to:
# process sys.argv and sys.path:
temppath =3D []
for i in range(len(sys.path)):
pathitem =3D os.path.abspath(sys.path[i])
if pathitem not in temppath:
temppath.append(pathitem)
sys.path =3D temppath
but is this really desirable (and does it even matter)? The new code =
will also drop duplicates which were present in PYTHONPATH. Is that good =
or bad?
Thanks,
Dave Harris
------=_NextPart_000_0005_01C2E0C7.65FE6600
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1141" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>When main() expands the current =
directory element=20
(" ") of sys.path, a duplicate item will be added to sys.path if the =
current=20
directory is a member of sys.path. For example, if my current directory =
is=20
"C:\\Python22\\Scripts", I end up with two instances for this directory. =
That=20
is: ['C:\\Python22\\Scripts', 'C:\\Python22\\Scripts',=20
'C:\\PYTHON22\\DLLs', 'C:\\PYTHON22\\lib', 'C:\\PYTHON22\\lib\\lib-tk',=20
'C:\\PYTHON22', 'C:\\PYTHON22\\lib\\site-packages']<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>The duplicate(s) can be eliminated by=20
changing:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> # process sys.argv =
and=20
sys.path:<BR> for i in=20
range(len(sys.path)):<BR> =
sys.path[i]=20
=3D os.path.abspath(sys.path[i])<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>to:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> # process sys.argv =
and=20
sys.path:<BR> temppath =3D []<BR> =
for i in=20
range(len(sys.path)):<BR> =
pathitem =3D=20
os.path.abspath(sys.path[i])<BR> if =
pathitem not in temppath:<BR> =20
temppath.append(pathitem)<BR> =
sys.path =3D=20
temppath<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>but is this really desirable (and does =
it even=20
matter)? The new code will also drop duplicates which were =
present in=20
PYTHONPATH. Is that good or bad?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Dave Harris</DIV></FONT></BODY></HTML>
------=_NextPart_000_0005_01C2E0C7.65FE6600--