3 ms·
I recently found several instances of hand-crafted for loops in our Python code with: j = 0 while condition(): ++j In Python, there is no "increment"
by deathanatos 7y ago
I recently found several instances of hand-crafted for loops in our Python code with:
j = 0
while condition():
++j
In Python, there is no "increment" operator, so `++j` is parsed as two unary plus operators: it's a no-op.
- dagw 7y agoI recently found the following bug in some python code at work x = 12 //10 What they where apparently trying to do was to change the value of x while commenting out the old value for reference. Except in python // is integer division and not comments so x was set to 1 instead of 12.
- alexeiz 7y agoThis is silly. One of my personal stupid mistakes in Python is forgetting to delete a trailing comma. The resulting code is still valid, because a trailing comma produces a tuple. a = b,
- dagw 7y agoOr accidentally forgetting a comma like in a = ["long", "list" "of", "strings] which become a = ["long", "listof", "strings"] due to automatic string concatenation
- guitarbill 7y agothe bugbear plugin for flake8 can warn about this: https://pypi.org/project/flake8-bugbear/ https://pypi.org/project/flake8-bugbear/