New submission from Håkon Hægland:

I have the following folder structure:

.
├── aaa
│   ├── bbb
│   │   ├── ccc.py
│   │   └── __init__.py
│   ├── bbb.py
│   └── __init__.py
├── __init__.py
└── t.py

./t.py:

import sys
sys.path = ['.']
import aaa.bbb
print(aaa.bbb.get_name())

./aaa/bbb.py:

def get_name():
    return "aaa/bbb"

however, when I run the main script:

$ python -B t.py 
Traceback (most recent call last):
  File "t.py", line 5, in <module>
    print(aaa.bbb.get_name())
AttributeError: module 'aaa.bbb' has no attribute 'get_name'

The reason is that there is also a package with name 'aaa.bbb' (i.e. file 
"./aaa/bbb/__init__.py") and python will see this package before it sees my 
module "./aaa/bbb.py" and will never load the module.

If this is correct, than this is a bad design in my opinion. I should be 
possible to use a module with the same name as a package. 

Thanks for considering this issue, and let me know if I can help improve Python 
at this point.

Note: I asked the question first at stackoverflow.com:
https://stackoverflow.com/q/44227763/2173773

----------
components: Interpreter Core
messages: 294682
nosy: hakonhagland
priority: normal
severity: normal
status: open
title: It should be possible to use a module name with the same name as a 
package name
type: enhancement

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30503>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to