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 :)

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