Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)
I came to know that generally people religiously follow the rules of PEP 8. I want to why is it so important? And what people find inconvenient or inadequate?

1 Answer

0 votes
by (107k points)

In my case, these are the two points where I find it is better not to follow PEP8 rules:

First case:

The rule for "79 characters per line" is totally absurd. Kindly check how unreadable code becomes when doing this:

class Rectangle(Blob):

    def __init__(self, width, height,

                 color='black', emphasis=None, highlight=0):

        if width == 0 and height == 0 and \

           color == 'red' and emphasis == 'strong' or \

           highlight > 100:

            raise ValueError("sorry, you lose")

        if width == 0 and height == 0 and (color == 'red' or

                                           emphasis is None):

            raise ValueError("I don't think so -- values are %s, %s" %

                             (width, height))

        Blob.__init__(self, width, height,

                      color, emphasis, highlight)

2nd Case:

- Imports should usually be on separate lines, e.g.:

    Yes: import os

         import sys

    No:  import sys, os

I always write simple imports together. I don't see any benefit to addressing them all on separate lines: all it does is add new lines from the top of each source file and turn something compact and easy to complex code. This is instantly readable and understandable:

import sys, os, time, gc, inspect, math, doctest

 Join this Python Training course now if you want to gain more knowledge in Python.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...