[Python-ideas] pep8 clarification, conditional top-level class/function leading newlines

Mark Lawrence breamoreboy at yahoo.co.uk
Sat Mar 2 15:06:09 CET 2013

On 02/03/2013 13:53, Dima Tisnek wrote:
> Hi,
> I'm trying to figure out how to space following code according to pep-8:

I ignore PEP 8 whenever I feel like it, it's not written in stone, it's 
simply a guide.

> try:
>      import x
>      class A:
>          def foo(self):
>              # magic using x
>              pass
> except ImportError:
>      import y
>      # different magic, using y
> typical conditions are try/except and if/elif/else, though I can
> imagine a true hacker to wrap top-level definitions in with x,
> possibly even for/else, while/else as well ;-)
> PEP-8 states to separate top-level class and functions by 2 blank
> lines and methods in a class by 1 blank line. This case falls into the
> crack, it's neither strictly top-level, nor a sub-level.
> option1: semantical, 2 lines before conditional top-levels
> option2: legalist, 1 line before any indented top-level
> pep8 tool only accepts option2

Which tool?  Any configuration option that you could set to change the 

> I think I would prefer option1; or explicitly leave it up user, then I
> can call option1 pep-8 compliant and someone else call option2 pep-8
> compliant as well.
> What do you think or prefer?

An irrelevance as far as I'm concerned.  I know that others have 
different opinions so I'd better du...

> Perhaps this was discussed ages ago and I can't find the traces?
> Thanks, d.


Mark Lawrence

More information about the Python-ideas mailing list