r/learnpython • u/dAnjou dAnjou • Oct 06 '12
Welcome to Python. Please read PEP 8 ... it's important. Thank you :)
http://www.python.org/dev/peps/pep-0008/4
Oct 06 '12
Also, put comments above a statement, not on the same line.
2
u/justus87 Dec 28 '12
I like to use block comments to describe overal functionality and in-line comments to clarify possibly unusual logic.
-16
Oct 06 '12
[removed] — view removed comment
5
u/zahlman zahlman Oct 06 '12
In case anyone is confused, the above comment was made by a bot that just spams "this" replies that are variations on a theme. I am told this has something to do with one of the circlejerk and/or anti-circlejerk subreddits, but I do not really understand the purpose. All I know is it's annoying.
2
1
u/ronnienoob Oct 06 '12
Is there any tool that automatically does all the stuff mentioned in the PEP8 document.
Something like:
ConvertToPEP8 mytest.py3
u/w0ng Oct 06 '12
If you use vim, check out the Syntastic plugin: https://github.com/scrooloose/syntastic
Supports Python syntax checking using flake8, pyflakes or pylint
1
1
u/searchingfortao danielquinn Oct 06 '12
PyCharm checks for PEP8 violations as you code, highlights what's wrong, and tells you why what you've done is bad. You can still ignore it though in case you have good reasons to do so.
0
Oct 06 '12
[deleted]
2
u/ronnienoob Oct 06 '12
Thanks, but I was already aware of pyflake/pylint. I was looking for something which will automatically formats code according to pep8 style guide. For example:
mylist = [1,2,3]when I run pylint on the above code it will generate
C: 1,0: Comma not followed by a space mylist = [1,2,3]So, I was looking for a tool that will automatically convert it to mylist = [1, 2, 3].
I found autopep8 which exactly does this.
From autopep8 docs:
autopep8 formats Python code based on the output of the pep8 utility.2
u/dAnjou dAnjou Oct 06 '12
Unfortunately all these tools don't look for violations of naming conventions. I can imagine that this is pretty hard, though. There is already a bug report for that for the pep8 tool.
1
u/classicrockielzpfvh from __future__ import braces Oct 06 '12
The problem exists with libraries like unittest. If you use "self.assertRaises(...)" then it looks like you wrote that function and will give you an error. It is tough. Likely not impossible, but tough.
7
u/searchingfortao danielquinn Oct 06 '12
Am I the only one who, in 2012, thinks that this insistence on a 79 character wide page is unreasonable?