Since Python was named after the Monte Python comedy troupe, it seems fitting to open the Roman package with a question:
... but apart from better sanitation and medicine and education and irrigation and public health and roads and a freshwater system and baths and public order... what have the Romans done for us?
-- The Life Of Brian, Monty Python
The answer: Roman Numerals!
This is a "hello world" example of how to create a Python package. It does so by going through the process of creating a package (roman
) that
- converting between roman numeral strings and integers
- converting between temperatures
This guide has been broken into several tags, so that the process can be followed. You can access different tag, clone this repo and use
git checkout tags/<tag name>
A series of blog posts walks through the process of creating a package from start to finish. The tags made available are
- v0.1: the idea We write the Roman numerals function, write a short module, and can import it from one directory.
- v0.2: documentation We write the docstrings of the function, and show best practices.
- v0.3: make a package
We write setup.py, and show how to install on our own system. We can also show how to install from github. - v0.4: writing tests
We write some unit tests, and introduce the
tox
package to allow easy testing. - v0.5: deploying We use (twine)[https://pypi.org/project/twine/] to post onto TestPyPI.
To install from tag v0.3 onward, use
# installation is easy!
$ python setup.py install
To uninstall (e.g. when updating) you can use pip
, even if you are only working locally
# so is uninstalling!
$ pip uninstall roman
Once installed, we can use this module with
>>> import roman
>>> roman.int_to_roman_string(4)
'IV'
>>> roman.roman_string_to_int('MMC')
2100
>>> roman.convert_all(0, 'C')
{'K': 273.15, 'F': 32, 'C': 0}
- This useful article on creating your first Python package
- The tox documentation
- The Python code on Project structure
- The Flask MegaTutorial for helping set up the git tag structure