Sample code for the article on for loops#620
Conversation
martin-martin
left a comment
There was a problem hiding this comment.
LGTM, two file name typos and a question about whitespaces around the self-documenting expression in f-strings.
|
|
||
| numbers = [1, 2, 3, 4, 5, 6] | ||
| for number in numbers: | ||
| print(f"{number = }") |
There was a problem hiding this comment.
flake8 compains and I was also wondering about it, I've generally only seen this used without whitespace:
| print(f"{number = }") | |
| print(f"{number=}") |
pycodestyle, which implements the check, seems to be stubborn about keeping it this way: PyCQA/pycodestyle#1201
$ flake8 break_continue.py
break_continue.py:11:20: E251 unexpected spaces around keyword / parameter equals
break_continue.py:11:22: E202 whitespace before '}'
break_continue.py:11:22: E251 unexpected spaces around keyword / parameter equalsBut I know you're using space around the equals sign also in the f-string tutorial.
So IDK, I guess the linters don't fail on it?
If you decide to change it, you'd also have to change it in the written tutorial.
There was a problem hiding this comment.
If I remember correctly, in one of my previous articles I used this feature without spaces and I guess it was Geir Arne who suggested adding the spaces for readability. However, I don't think this is a written rule.
There was a problem hiding this comment.
Ok, yeah I'm fine with leaving it considering it passes our linter checks. @gahjelle should we note this somewhere, that we'll ignore E251 and E202 for these cases?
| points = [(1, 4), (3, 6), (7, 3)] | ||
|
|
||
| for x, y in points: | ||
| print(f"{x = } and {y = }") |
There was a problem hiding this comment.
Same as in the previous comment, flake8 doesn't like the whitespace:
| print(f"{x = } and {y = }") | |
| print(f"{x=} and {y=}") |
Where to put new files:
my-awesome-articleHow to merge your changes: