Import semantics?

Dan Stromberg drsalists at gmail.com
Sat Jun 9 02:02:03 CEST 2012


On Fri, Jun 8, 2012 at 3:48 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:

> On Fri, Jun 8, 2012 at 4:24 PM, Dan Stromberg <drsalists at gmail.com> wrote:
> > Am I misinterpreting this?  It seems like according to the PEP, I should
> > have still been able to import treap.py despite having a treap/.  But I
> > couldn't; I had to rename treap/ to treap-dir/ first.
>
> That's how I understand it.  The existence of a module or regular
> package 'foo' anywhere in the path should trump the creation of a
> 'foo' namespace package, even if the namespace package would be
> earlier in the path.  Ar you sure you don't have an __init__.py in
> your treap directory?
>


The issue replicated in a minimal way (it's in the ticket too):

 dstromberg at zareason-limbo6000a /tmp/tt $ mv treap treap-dir

dstromberg at zareason-limbo6000a /tmp/tt $ /usr/local/cpython-3.3/bin/python
-c 'import sys; print(sys.path); import treap; t = treap.treap()'
['', '/usr/local/cpython-3.3/lib/python33.zip',
'/usr/local/cpython-3.3/lib/python3.3',
'/usr/local/cpython-3.3/lib/python3.3/plat-linux',
'/usr/local/cpython-3.3/lib/python3.3/lib-dynload',
'/usr/local/cpython-3.3/lib/python3.3/site-packages']

dstromberg at zareason-limbo6000a /tmp/tt $ mv treap-dir/ treap

dstromberg at zareason-limbo6000a /tmp/tt $ /usr/local/cpython-3.3/bin/python
-c 'import sys; print(sys.path); import treap; t = treap.treap()'
['', '/usr/local/cpython-3.3/lib/python33.zip',
'/usr/local/cpython-3.3/lib/python3.3',
'/usr/local/cpython-3.3/lib/python3.3/plat-linux',
'/usr/local/cpython-3.3/lib/python3.3/lib-dynload',
'/usr/local/cpython-3.3/lib/python3.3/site-packages']
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'treap'

dstromberg at zareason-limbo6000a /tmp/tt $ ls -l treap/__init__.py
ls: cannot access treap/__init__.py: No such file or directory

dstromberg at zareason-limbo6000a /tmp/tt $ /usr/local/cpython-3.3/bin/python
Python 3.3.0a4 (default, Jun  8 2012, 14:14:41)
[GCC 4.6.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120608/aff59b5a/attachment.html>


More information about the Python-list mailing list