An example project for python project structuring.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
arithmetic
.gitignore
README.md
setup.py

README.md

Arithmetic

Just a package to demonstrate proper project stucturing in python.

Project structure:

$ pwd
~/src/python/Arithmetic/arithmetic

$ tree
.
├── arithmetic
│   ├── division
│   │   ├── divide.py
│   │   ├── __init__.py
│   │   ├── __main__.py
│   │   └── __pycache__
│   ├── __init__.py
│   ├── __main__.py
│   ├── multiplication
│   │   ├── __init__.py
│   │   ├── __main__.py
│   │   ├── multiply.py
│   │   └── __pycache__
│   └── tests
│       ├── division
│       │   └── test_divide.py
│       ├── __init__.py
│       ├── __main__.py
│       └── multiplication
│           └── test_multiply.py

Running modules individually.

  • Arithmetic: python -m arithmetic
  • Division: python -m arithmetic.division
  • Multiplication: python -m arithmetic.multiplication
  • Tests: python -m arithmetic.tests

However the following for example fails. How can I make them work and is it necessary?

$ python arithmetic/tests/test_divide.py 
Traceback (most recent call last):
  File "arithmetic/tests/test_divide.py", line 2, in <module>
    import arithmetic.divide as divide
ImportError: No module named 'arithmetic'


$ python arithmetic/tests/test_multiply.py 
Traceback (most recent call last):
  File "arithmetic/tests/test_multiply.py", line 1, in <module>
    import arithmetic.multiply as multiply
ImportError: No module named 'arithmetic'