4 ms·
Ask HN: Python Script Best Practices?
I recently stumbled on this article about Shell Script Best Practices (https://sharats.me/posts/shell-script-best-practices/) here on HN and appreciated the format (concise, curated, well explained, based on experience).
I was wondering if someone knows of a similar ressource for python ?
- j0hnyl 4y agohttps://peps.python.org/pep-0008/ https://peps.python.org/pep-0008/
- nuancebydefault 4y agoAlso, the conformity to pep8 can be easily automatically checked. I remember when using pycharm as an editor, it was rather easy to comply. As a side note, I remember i learned a lot of tricks that make your code more easy to read/maintain after searching for articles about "pythonic python code"
- deleted 4y ago[deleted]
- 4oo4 4y agoUse a linter, personally pylint has helped me learn to write more "Pythonic" code. If you're using vscode, you can easily integrate it or any other python linter. https://learn.microsoft.com/en-us/visualstudio/python/linting-python-code?view=vs-2022 https://learn.microsoft.com/en-us/visualstudio/python/lintin... If you also want a linter for bash, check out shellcheck: https://github.com/koalaman/shellcheck https://github.com/koalaman/shellcheck
- wodenokoto 4y agoRead pep8, as others suggest, but don’t use a linter. > However, know when to be inconsistent – sometimes style guide recommendations just aren’t applicable. When in doubt, use your best judgment. Look at other examples and decide what looks best. -pep8
- wonkyspecs 4y agoTo follow up on this, if you've got a spare hour, one of the python core developers has a great demo of how pep8 can sometimes be blinding to larger issues https://www.youtube.com/watch?v=wf-BqAjZb8M https://www.youtube.com/watch?v=wf-BqAjZb8M That said, most of what pep8 says is great to follow in the vast majority of cases.