Reputation: 535
I'm in bind with regard to the naming of the directory structure in my python package. The problem is that I'm calling the package the same name as the directory containing the source code and the main class. Like this:
```
Bucha
\ docs
| examples
| bucha
\ class1.py
| class2.py
| bucha.py (which contains a class Bucha)
| tests
```
I've done a local pip install, so when I want to instantiate Bucha I have to import like this
from bucha.bucha import Bucha
which is, of course, ridiculous.
Any suggestions on improving this naming? Is there a pep guideline for this?
Upvotes: 0
Views: 86
Reputation: 2881
You can add __init__.py
to the folders where you import things.
For instance, I did this:
$ mkdir -p bucha/bucha
$ touch bucha/bucha/Bucha.py
$ subl .
$ touch bucha/bucha/__init__.py
$ touch bucha/__init__.py
$ touch __init__.py
$ python -c 'import bucha'
bucha/bucha/__init__.py
bucha/bucha/Bucha.py
bucha/__init__.py
These are the contents of the files:
$ cat bucha/bucha/Bucha.py
print(__file__)
$ cat bucha/bucha/__init__.py
print(__file__)$
$ cat bucha/__init__.py
import bucha.Bucha as Bucha
print(__file__)
$ cat __init__.py
from bucha import Bucha
print(__file__)
Upvotes: 1