
Tue, February 6, 2018
Create reusable codes across Projects and potentially ShareIt!
I am programming in modules, and it is easy to share *.py
within a project. How?
- Always code in a
def
or aclass
. Never code outside one. - For main code, never code outside a block, but code main code inside
if _<i>name_</i> == '__main__'
: - Share using
import ...
orfrom ... import ...
But sharing across projects is a different story, but today, I found out how:- https://python-packaging.readthedocs.io/en/latest/
- When you have done the packaging, you can run
pip install -e .
to share it for any*.py
files you will run in the future. - This will also facilitate others to run
pip install .
, and they can use your git now. (They will have to clone your git first, though.) - You can publish on PyPI using
python setup.py register
- Editing
setup.py
a bit, it ispy2app
/py2exe
.
Good luck modular programming!
Tags: python