[Tutor] Adding a search path PERMANENTLY?

Brian van den Broek bvande at po-box.mcgill.ca
Sat Jul 10 22:10:48 CEST 2004


Hee-Seng Kye said unto the world upon 10/07/2004 14:58:

> Hi, Brian.  Thanks for your response.  Yes, I'm on Mac, but I mainly 
> work on UNIX shell (tcsh).  Someone else (a.k.a orbitz) replied and 
> directed me to the source, so the problem is solved.
> 
> I do have a question for you though.  You specifically mention that 
> 'setting the PYTHONPATH will put the specified dirs ahead of the 
> standard lib dirs in sys.path,' and that's exactly what I experienced.  
> Is new path supposed be placed where it is placed?  Does it have any 
> meaning other than the fact that it will be searched before the standard 
> lib paths?  You seem to be very specific about it, so I'm just wondering.
> 
> Thanks a lot for your response.
> 
> Best,
> 
> Kye
> 
> p.s. For those who might be asking the same question in the future, this 
> is how it's done on tcsh.  Put the following line in .tcshrc (or .cshrc 
> if you are on csh, I think...):
> 
> setenv PYTHONPATH "your desired path here"
> 
> It was confusing to me at first due to the absence of the '=' sign.  The 
> above syntax should work.
> 
> 

<SNIP>

Hi Kye,

my understanding is that PYTHONPATH places the new dirs in sys.path before 
the standard lib dirs and .pth files after. (This is from the docs.) This 
mattered to me as I had wanted after to prevent accidentally over-riding 
standard lib, etc modules if I were to inadvertently give one of my 
modules the same name as an existing module.

So, use PYTHONPATH if you want to allow the possibility of over-riding 
standard modules (or if you are not worried about doing so by accident) 
and use .pth files if you want to guard against naming conflicts. Since 
.pth additions come after you can use the same names as standard lib 
modules without breaking anything. Of course your same named modules won't 
get imported because the standard lib ones will be found first. But this 
seems the sort of thing you'd realize at the time; the other way round, I 
worried that weeks or months later I could be bit by a naming conflict and 
have a hard time figuring it out at the time.

I'm not sure that that answers your question. But it seems to me that the 
two options so differ precisely so as to allow for this sort of choice in 
behaviour. (Note though that I am merely reading the docs and drawing what 
are, I hope, reasonable inferences; I am no Python-guru ;-)

You mentioned being directed to the sources. That didn't come through the 
list. Was it site.py or somewhere else?

Best to all,

Brian vdB



More information about the Tutor mailing list