
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
What are the best practices to organize Python modules?
Here is a sample project that shows a very good way to structure your projects: https://github.com/kennethreitz/samplemod. The project is about creating the "sample" module. The directory structure looks as follows:
README.rst LICENSE setup.py requirements.txt sample/__init__.py sample/core.py sample/helpers.py docs/conf.py docs/index.rst tests/test_basic.py tests/test_advanced.py
The README.rst file: This file is for giving a brief description of the module, how to set it up, how to use it, etc.
LICENSE: Contains license text and any copyright claims.
setup.py: It is Python's answer to a multi-platform installer and make file. If you’re familiar with command line installations, then make && make install translates to python setup.py build && python setup.py install. So it is used to build your project on user machine.
requirements.txt: A Pip requirements file should specify the dependencies required to contribute to the project: testing, building, and generating documentation. If your project has no development dependencies, or you prefer development environment setup via setup.py, this file is unnecessary.
docs/: This directory contains the documentation for your project.
tests/: All your tests should reside in this directory. Initially you'll have a single test file. As they start to grow, you can structure your tests like your module directory.
sample/: This directory contains your actual module code. If your module consists of only a single file, you can place it directly in the root of your repository as sample.py. Your library does not belong in an ambiguous src or python subdirectory. This will contain a __init__.py file if you want this module to reside within a package.
- Related Articles
- What are common practices for modifying Python modules?
- What are Python coding standards/best practices?
- How to organize Python classes in modules and/or packages
- What are the best practices for using loops in Python?
- What are the best practices for exception handling in Python?
- What are the best Python 2.7 modules for data mining?
- What are the best practices for using if statements in Python?
- What are the Best Practices in Visual Marketing?
- What are the “best practices” for using import in a Python module?
- What are the best practices to improve jQuery selector performance?
- What are the Best Practices to Improve CRM User Adoption?
- What are the best practices for committing in Git?
- What are the best practices to be followed while using JavaScript?
- What are the best practices for function overloading in JavaScript?
- What are favicon best practices regarding size and format?
