How do I format a long url in python comment and still match PEP8

In a block comment, I want to link to URLs longer than 80 characters.

What is the preferred arrangement for displaying this URL?

I know bit.ly is an option, but the URL itself is descriptive. Shortening it up and then having a nested comment describing the shortened URL seems like a crappy solution.

+50
python pep8
May 24 '12 at 14:47
source share
7 answers

Do not break URL:

# A Foolish Consistency is the Hobgoblin of Little Minds [1] # [1]: http://www.python.org/dev/peps/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds 
+54
May 24 '12 at 14:56
source share

From PEP8

But the most important thing: to know when to be inconsistent - sometimes the style guide simply does not apply. When in doubt, use your best judgment. Take a look at other examples and decide what looks best. And feel free to ask!

Two good reasons for breaking a rule are:

  • When applying the rule, the code will become less readable even for those who are used to reading the code following the rules.

Personally, I would use this advice and would rather leave a full descriptive URL in your comment for people.

+51
May 24 '12 at 14:55
source share

I would say leave it ...

PEP20 :

Special cases are not complex enough to break the rules.

Although practicality surpasses purity.

It is more practical to be able to quickly copy / paste the URL to delete the lines when pasting into the browser.

+20
May 24 '12 at 14:55
source share

You can use # noqa at the end of a line to stop PEP8 / Flake8 from doing this check. This is permitted by PEP8 through:

Special cases are not complex enough to break the rules.

+18
Jul 30 '14 at 10:43
source share

If you are using flake8:

 """ long-url: http://stackoverflow.com/questions/10739843/how-should-i-format-a-long-url-in-a-python-comment-and-still-be-pep8-compliant """ # noqa 
+5
Sep 29 '16 at 10:41
source share
+2
Apr 08 '13 at 6:42 on
source share

My version:

 URL = ('http://stackoverflow.com/questions/10739843/' 'how-should-i-format-a-long-url-in-a-python-' 'comment-and-still-be-pep8-compliant') 
-3
May 24 '12 at 10:54 pm
source share



All Articles