coding style - Python PEP 8: Blank lines at the beginning of a module -
there question treat not talk points interested.
pep 8 says blank lines:
separate top-level function , class definitions 2 blank lines.
then if have:
a module class:
# -*- coding: utf-8 -*- class a(object): pass
do separate begin of class , encoding comment 2 blank lines?
a module import statement , classes:
# -*- coding: utf-8 -*- import module class b(object): pass class c(object): pass
do separate import statement , encoding comment 1 blank line?
and import statement , begin of class 2 blank lines?
and main module:
#!/usr/bin/env python # -*- coding: utf-8 -*- import module def main(): = module.a() return 0 if __name__ == '__main__': status = main()
do separate import statement , top-level function 2 blank lines?
and end of top-level function , conditional statement 2 blank lines?
there's python module called pep8 can check code see if complies pep8 guidelines.
i tried running pep8 on examples listed, , several variants of them, , in general, pep8 program accepted of them compliant pep8 guidelines. basically, answer questions yes.
there exist level of subjectivity -- example, have 2 or 1 newlines between main function , if __name__ == '__main__'
segment. however, wouldn't worry pep8 compliance -- download , install pep8 program along other code analyzers (such pylint). long code passing tests, it's enough.
Comments
Post a Comment