Although I read what PEP8 has to say about comments, I'm still curious about how best to write single lines of code in Python.
The above example is good if the line of code in question is very short:
x = x + 1
But if the line or comment is longer, things get more complicated. For instance:
import numpy as np import matplotlib.pyplot as plt a = np.random.random([3, 3]) b = np.random.random([3, 3]) coords = zip(a.ravel(), b.ravel())
The comment is quite long, as is the line of code, which takes longer than the allowed line length.
I usually put a comment above the line, but then it is unclear whether the comment applies to the plt line or not:
I try to get around this by inserting a new line between the two lines:
I did this too, but it seems a bit bloated:
""" match elements of a with elements of b ignoring shape """
Is there an accepted way to do this?
source share