DEV Community

Discussion on: 20 useful Python tips and tricks you should know

Collapse
 
thefern profile image
Fernando B 🚀

I'll add a few more to the awesome list!

Comprehension list, I actually like for loops written in full but if you want to save space here and there comp. lists can help with that:

[ expression for item in list if conditional ]

for item in list:
    if conditional:
        expression

I like to run pep8 linter sometimes on cmd line, of course you can have a linter on your text editor too, below is the way to do it from cmd line:

github.com/PyCQA/pycodestyle

pip install pycodestyle

$ pycodestyle --first optparse.py
optparse.py:69:11: E401 multiple imports on one line
optparse.py:77:1: E302 expected 2 blank lines, found 1
optparse.py:88:5: E301 expected 1 blank line, found 0
optparse.py:222:34: W602 deprecated form of raising exception
optparse.py:347:31: E211 whitespace before '('
optparse.py:357:17: E201 whitespace after '{'
optparse.py:472:29: E221 multiple spaces before operator
optparse.py:544:21: W601 .has_key() is deprecated, use 'in'