Reputation: 154
I have created a Python package... with nothing in it. All it is, is the simple structure from the Python packaging tutorial.
/example_pkg
/example_pkg
__init__.py
setup.py
LICENSE
README.md
Where do you put the files you want to create? In the root folder or somewhere else?
Upvotes: 1
Views: 162
Reputation: 662
I think you can start by simply putting all your source code files in the root directory. It might be a good idea though to put different files (eg. images) in a dedicated folder.
When your project becomes larger it may be a good idea to create more subfolders ("packages") but this really depends on your case. From The Zen of Python follows that you should keep your package structure simple.
>>> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
(emphasis added)
So basically it is up to you but you should keep these this in mind.
Upvotes: 0
Reputation: 4201
You can divide your package up into sub-packages and modules in whatever way makes sense to you (using new files for modules and directories for packages). I would start by looking at the structure of some of the popular Python packages in order to get well rounded view of what the best practices are.
Take a look through some of the below packages to get a feel for what's possible and what is considered best practise. Pay particular attention to the setup.py
and __init__.py
files and the directory structure of the project as a whole.
Upvotes: 0
Reputation: 9994
In the Python ecosystem, there's (at least) two related, but different things called "package":
__init__.py
filepip
and related toolsFollowing the instructions you've linked, you've probably created a structure for the latter (a directory containing setup.py
etc.) containing one package of the first type (the inner example_pkg
directory.)
example_pkg/
├── example_pkg/
│ └── __init__.py
├── LICENSE
├── README.md
└── setup.py
Usually, you should put your library's code into the package of the first type (the inner example_pkg
folder), so that it is properly contained by that namespace.
example_pkg/
├── example_pkg/
│ ├── __init__.py <--- put your code here
| ├── a_sub_pkg/
│ │ ├── __init__.py <-- or maybe here
│ │ └── something.py <-- or here
│ └── another_thing.py <-- or here
├── LICENSE
├── README.md
└── setup.py
Upvotes: 1
Reputation: 389
Your files should be under example_pkg which has the __init__
in the example.
Each folder that represents a package or sub-package should have a __init__.py
file.
Upvotes: 2