[Python-Dev] Draft: PEP for imports

Nick Coghlan ncoghlan at iinet.net.au
Thu Jan 22 00:26:31 EST 2004


Aahz wrote:

> On Tue, Jan 20, 2004, Batista, Facundo wrote:
> 
>>I don't use packages, but when I read the tutorial first time, I wondered
>>why, if the packages appeared to solve a 'pack into a directory' problem,
>>the names were joined with '.' instead of '/'. Later I found some other uses
>>to the 'unix path' notation.
>>
>>For example:
>>
>>- Module inside a package:  import package/module
>>
>>- Relative import:  import ../../otherpack/webmodules/somemodule
> 
> 
> Haven't seen any support for this; in the absence of support, I'll have
> to assume that it's a non-starter.

It has some appeal to me, as when we use the standard 'dot' notation, 
Python is invoking some magic on our behalf to search several 'standard' 
locations (the Python standard library, site-packages, sys.path, current 
directory(?) are the locations I am aware of).

I believe the proposal is to drop the current directory from that list 
of locations searched, which leaves the unresolved question of how to 
spell an explicit request for a relative import.

Since it _is_ the file system heirarchy we're traversing in a relative 
import, why _not_ use a Unix-style relative path?

So:

   from ./mypy import stuff
   from ../mypkg2/mypy2 import other_stuff

(I don't see any reason to change the proposal to require the 'from ... 
import ...' arrangement when doing relative imports)

To import an entire module from the current directory, it may be enough 
to allow a trailing slash:

   from ./ import mypy

Certainly, it would be easy to understand - and the slash characters 
would hopefully be enough to signal the import machinery that a relative 
import is being requested.

Regards,
Nick.




-- 
Nick Coghlan               |     Brisbane, Australia
Email: ncoghlan at email.com  | Mobile: +61 409 573 268




More information about the Python-Dev mailing list