{"componentChunkName":"component---src-templates-post-tsx","path":"/posts/2018/02/reusable-python/","result":{"data":{"markdownRemark":{"fields":{"slug":"/2018/02/reusable-python/"},"frontmatter":{"title":"Create reusable codes across Projects and potentially ShareIt!","tag":["python"],"image":"https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcRiJmcz8lmfxBjO1Svz-urf6yKiZ3RSnYpx2m2F-dnjp_SO204V"},"correctedDateEpoch":1517936400000,"html":"<p>I am programming in modules, and it is easy to share <code>*.py</code> within a project. How?</p>\n<!-- excerpt_separator -->\n<ul>\n<li>Always code in a <code>def</code> or a <code>class</code>. Never code outside one.</li>\n<li>For main code, never code outside a block, but code main code inside <code>if __name__ == '__main__'</code>:</li>\n<li>Share using <code>import ...</code> or <code>from ... import ...</code></li>\n</ul>\n<p>But sharing across projects is a different story, but today, I found out how:- <a href=\"https://python-packaging.readthedocs.io/en/latest/\">https://python-packaging.readthedocs.io/en/latest/</a></p>\n<ul>\n<li>When you have done the packaging, you can run <code>pip install -e .</code> to share it for any <code>*.py</code> files you will run in the future.</li>\n<li>This will also facilitate others to run <code>pip install .</code>, and they can use your git now. (They will have to clone your git first, though.)</li>\n<li>You can publish on PyPI using <code>python setup.py register</code></li>\n<li>Editing <code>setup.py</code> a bit, it is <code>py2app</code>/<code>py2exe</code>.</li>\n</ul>\n<p>Good luck modular programming!</p>"}},"pageContext":{"slug":"/2018/02/reusable-python/"}}}