[Patches] [ python-Patches-946373 ] do not add directory of sys.argv[0] into sys.path

SourceForge.net noreply at sourceforge.net
Fri May 7 19:45:39 EDT 2004


Patches item #946373, was opened at 2004-05-02 05:51
Message generated for change (Comment added) made by isandler
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=946373&group_id=5470

Category: Core (C code)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: wrobell (wrobell)
Assigned to: Nobody/Anonymous (nobody)
Summary: do not add directory of sys.argv[0] into sys.path

Initial Comment:
Python adds magically directory of sys.argv[0] into
sys.path, i.e.

>>> import sys
>>> sys.path
['', '/usr/lib/python23.zip', '/usr/share/python2.3',
'/usr/share/python2.3/plat-linux2',
'/usr/share/python2.3/lib-tk',
'/usr/lib/python2.3/lib-dynload',
'/usr/lib/python2.3/site-packages',
'/usr/lib/python2.3/site-packages/gtk-2.0',
'/usr/share/python2.3/site-packages']

where '' (or /usr/bin when executed script is in
/usr/bin directory, etc.) is added automatically.

It is useful in many circumstances but fails when name
conflict occurs.
For example, create getpass.py or pdb.py scripts which
import getpass and pdb modules. Script names conflict
with modules names and modules
are not going to be imported because path to the
scripts is appended
into sys.path, so a script is imported instead of a module.

The solutions:
1. User of script with conflicting name (i.e.
getpass.py or timeit.py)
can set PYTHONPATH to system library path, i.e.
/usr/lib/python2.3.
2. User can modify the script to delete site.path[0].
3. User can rename the script.
4. Python can be modified to not add magically
directory of sys.argv[0].

The 1. is a tricky and not intuitive and quite funny:
set PYTHONPATH to system library path to import system
module (and only in
specific circumstances). ;-P

The 2. is a dirty hack: hey, we gonna import system
module, ain't it?

The 3. is, IMHO, not acceptable because there is more
than 200 python system modules, more in the future and
user cannot be forced to maintain script names blacklist.

The 4. is only acceptable, IMHO. It makes python more
inconvenient
but gives no trouble when names conflict occurs.
Moreover, fourth
solution makes python more standard with other languages
behaviour, i.e. one has to set CLASSPATH to load Java
classes.

Maybe there is another solution, but...

Patch attached.

----------------------------------------------------------------------

Comment By: Ilya Sandler (isandler)
Date: 2004-05-07 16:45

Message:
Logged In: YES 
user_id=971153


Would not this cause serious backward compatibility problems??




----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=946373&group_id=5470



More information about the Patches mailing list