[Python-Dev] Re: .pth files in current or script directory

Richard Cooper python-dev at richardcooper.net
Tue May 25 19:02:11 EDT 2004


From: Richard Cooper <anon at spam-trap.richardcooper.net>
Date: Wed May 19, 2004  1:34:12  pm Europe/London
To: python-dev at python.org
Subject: Re: .pth files in current or script directory

Seems this message got lost somewhere. So subscribing and resending.

Greg Ewing wrote:
 > Richard Cooper <anon at server15.ukservers.net>:
 >
 > > When a module is imported, its import search path includes 
everything it
 > > does now PLUS the directory that is the top of the module's 
enclosing
 > > package structure.
 >
 > I don't see how that changes anything, since in order to get
 > imported in the first place, the module's top-level package has
 > to already be on the module search path somehow.

Sorry, slip of the brain. I meant "When a module is executed ..."

Aahz wrote:
 > What's wrong with PEP 328?

Nothing, I think it's great. However it talks about making import 
statement
absolute by default (searching sys.path only) without worrying about 
how a
package gets on sys.path in the first place.

Currently a module can't import (absolutely) from it's own package 
unless:
1) Its package is in one of a few special places (like site-packages)
2) The package is in PYTHONPATH
3) The module does some sys.path tinkering before the import

None of these are great solutions. My initial problem was that I picked 
the
PYTHONPATH solution which (as you all know) turns out to be a real pain
when working on cvs branches.

If the top of the containing package got added to sys.path when a module
is executed then importing (absolutely) from your own package would
(I think) just work. And given that PEP 328 is going to encourage 
absolute
imports and is going to be changing import semantics anyway, I think 
this
would be a nice feature to have.

Rich




More information about the Python-Dev mailing list