This is how I write Python code.
Later bullet points take precedence:
- PEP 8.
- Write what meta-programming would have produced.
- Vertical alignment is desirable.
- Function names are mixedCase.
- Comments don't have to be complete sentences. Shorter comments improve readability.
- Comments can be in Chinese if they correspond to another document in Chinese, e.g. a paper.
- Avoid abbreviations in names, unless they are well established. Long variable names usually don't affect readability, or even typability.
x.source_addr[i ] = 8
x. dest_addr[i + 1] = 9
The easiest way to meta-program is to treat code segments as repeating chunks.
Write single-element tuple as (1, )
. This way, it generalizes to two-element tuple: (1, 2, )
.
Leave a trailing whitespace after the trailing comma:
for a, b, c in zip(
node_pair, newLink(), reversed(node_pair),
):
This way, adding an element is simply appending a code segment.
Trailing whitespace in string literals.
'I have a dream. '
Should I use file=f
or file = f
for optional arguments?