elements-of-python-style
elements-of-python-style copied to clipboard
Goes beyond PEP8 to discuss what makes Python code feel great. A Strunk & White for Python.
@amontalenti , I hope this saves you some time... F-strings are [new in Python 3.6](https://docs.python.org/3/reference/lexical_analysis.html#f-strings) You may find them easier to compose and to read `f"result: {value:{width}.{precision}}"`. The tradeoffs are...
I was listening to a Python coding standards talk today and there was a lot of discussion of `typing` in 3.x, `mypy`, and other related tools. This obviously introduces a...
In a chat, @ngoldbaum mentioned: "I disagree that libraries should pin their requirements. A library wants to support as wide a range of dependency versions as is practical, so that...
Link to the flake8 config docs is broken here: https://github.com/amontalenti/elements-of-python-style/blame/master/README.md#L36 Would have offered a PR, but there were a couple of pages that might have fulfilled the intent: * https://flake8.pycqa.org/en/latest/user/configuration.html...
ReStructured Text is typically abbreviated as RST, not reST, so I've changed that here since reST is too much like REST. I've also added a parenthetical spelling out what RST...
The default Sphinx style for docstrings is hard to remember and not especially legible (unless rendered). Multiple friendlier alternatives exist, including the popular NumPy and Google formats, both of which...
The [section on string formatting](https://github.com/amontalenti/elements-of-python-style#strformat-vs-overloaded-format-) includes `str.format()` and string overloading (`%`). As of Python 3.6, [f-strings](https://www.python.org/dev/peps/pep-0498/) are also supported.
See the Intermezzo here: https://docs.python.org/3/tutorial/controlflow.html#intermezzo-coding-style Which does a good job of summarizing PEP8 and benefits from existing in the official Python tutorial.
Since Python3.5 supports for type hints. It could be better than writing docstring at sometimes. Such as follow example. We can learn from code a lot directly rather than docstring....