|
Python Source Code Formatting |
|
|
|
|
Written by Gordon Tillman
|
|
Thursday, 04 December 2008 19:25 |
Source Code Formatting
PEP 8 - Style Guide for Python Code is what you should follow when writing your Python programs. There is a nifty little Python program called pep8.py that you can run against your source code to check your work. Here is an example. For this example I'm going to assume you have ~/bin/pep8.py and you want to check a Python program called test.py that is in your current directory.
$ ~/bin/pep8.py --repeat test.py
rip:21:80: E501 line too long (199 characters)
rip:59:1: W291 trailing whitespace
rip:61:1: W291 trailing whitespace
rip:63:1: W291 trailing whitespace
rip:66:1: W291 trailing whitespace
rip:68:1: W291 trailing whitespace
rip:73:1: W291 trailing whitespace
rip:78:8: W291 trailing whitespace
rip:79:1: W291 trailing whitespace
rip:93:1: W291 trailing whitespace
rip:107:80: E501 line too long (91 characters)
rip:108:1: W291 trailing whitespace
rip:110:1: W291 trailing whitespace
rip:111:34: W291 trailing whitespace
rip:117:1: W291 trailing whitespace
rip:122:1: W291 trailing whitespace
rip:126:10: W291 trailing whitespace
rip:140:80: E501 line too long (105 characters)
rip:141:80: E501 line too long (103 characters)
rip:143:1: W291 trailing whitespace
rip:146:1: W291 trailing whitespace
rip:147:1: W391 blank line at end of file
Obviously this program needs some work! |
|
Last Updated on Thursday, 04 December 2008 19:43 |