There is a question who treat about this but not talk about all the points I interested.
PEP 8 says about blank lines:
Separate top-level function and class definitions with two blank lines.
Then if you have:
A module with only a class:
# -*- coding: utf-8 -*- class A(object): pass
Do you separate the begin of the class and the encoding comment with two blank lines?
A module with import statement and classes:
# -*- coding: utf-8 -*- import module class B(object): pass class C(object): pass
Do you separate the import statement and the encoding comment with one blank line?
And the import statement and the begin of the class with two blank lines?
And a main module:
#!/usr/bin/env python # -*- coding: utf-8 -*- import module def main(): a = module.A() return 0 if __name__ == '__main__': status = main()
Do you separate the import statement and the top-level function with two blank lines?
And the end of the top-level function and the conditional statement with two blank lines?