Python Coding Standards


Coding standards is not only to avoid ugly code. It is very useful to get responses quickly.

You can see the python coding standards in PEP8

There are many third party packages to test standards you used in your modules. Especially pylint package is very simple to use.

To install pylint follow the link


Here I write two modules having same logic. First one( is written with standards and another one( is not having standards.

#### With Standards ( ####

Test the coding standards


from datetime import datetime, timedelta
def with_standard():

    Test the coding standards


    st_time = datetime.\
    data = {'los':30,
    for city, provider_count in data.\
        if (city != \[code\] and \
            provider_count < 100):
    end_time = (datetime.\
                now() - timedelta(hours=st_time.hour,
    print "To get response the script took %s \
(Hour:Minutes:Seconds MicroSeconds)" % (end_time.\
                                            strftime('%H:%M:%S %f'))
    return ()

if __name__ == '__main__':

### End of Module ###

### Without standards ( ###

from datetime import datetime,timedelta
def without_standard():
    st_time =
    data = {'los':30,'san':60,'can':80,'New':20}
    for key,value in data.iteritems():
        if key != \[/code\] and value < 100:
    end_time = - timedelta(hours=st_time.hour,seconds=st_time.second,microseconds=st_time.microsecond)
    print "To get response the script took %s (Hour:Minutes:Seconds MicroSeconds)" %(end_time.strftime('%H:%M:%S %f'))
    return ()
if __name__ == '__main__':

### End of Module ###

Test standards:

If we execute pylint command from command line, it will give 10.00/10 as the standards rate.

When we execute pylint command, it will give 3.85/10 as the rate. 

Now you can see a huge difference between standards' rate.

So try to follow standards in your future modules :)

Leave comments

  • I also check my code with pylint. It is hard to achieve 10/10 though, especially since I do not like 80 chars limit.
    Were your able to achieve 10/10 for your whole project?

    • Joseph Reed
  • There are two ways to disable standards check for particular occurrences.

    For example If you want to disable 80 chars limit, you can follow either one of the below things:
    1. Standard code for 80 Char limit is C0301. In top of your module you can add the line,
    # pylint: disable=C0301
    2. You can pass it as command line arguments. For example, If you execute the command,
    pylint --disable=C0301

    In those 2 ways we can disable standards. But it is not recommended.

    You can read pylint docs for reference in

    It is bit difficult to achieve 10/10 rate for projects already developed.

    But in future projects we can achieve 10/10 rate by testing each modules once they are developed.

    • Karthik

Copyright(c) 2017 -
By using this website, you signify your acceptance of Terms and Conditions and Privacy Policy
All rights reserved