Size: 2866
Comment:
|
Size: 3776
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 108: | Line 108: |
}}} |
|
Line 156: | Line 153: |
== Other resources == * [[http://code.google.com/p/soc/wiki/PythonStyleGuide|PythonStyleGuide - soc - Style guide for Python code contributed to Melange - SoC (Spice of Creation) - Google Project Hosting]] * [[https://google.github.io/styleguide/pyguide.html|Google Python Style Guide]] * [[https://github.com/google/yapf|google/yapf: A formatter for Python files]]. clang-format-like, similar to gofmt == Lectures == === PyCon 2015: Beyond PEP8: Best practices for beautiful intelligible code === [[https://www.youtube.com/watch?v=wf-BqAjZb8M|Raymond Hettinger - Beyond PEP 8 -- Best practices for beautiful intelligible code - PyCon 2015 - YouTube]] * Adding an arbitrary line break to make a line <= 80 characters, shortening variable names, etc does NOT make code better. * "Foolish consistency is the hobgoblin of little minds" — right at the top of PEP8, people read right through it! |
File organization
- The Encoding
- The Copyright
- The License
- The Documentation String
- The Imports
- Authorship information
- The Code
1 # -*- coding: UTF-8 -*-
2 # Copyright (C) YEARS AUTHOR-NAME <AUTHOR-EMAIL>
3
4
5 __author__ = "Rob Knight, Gavin Huttley, and Peter Maxwell"
6 __copyright__ = "Copyright 2007, The Cogent Project"
7 __credits__ = ["Rob Knight", "Peter Maxwell", "Gavin Huttley",
8 "Matthew Wakefield"]
9 __license__ = "GPL"
10 __version__ = "1.0.1"
11 __maintainer__ = "Rob Knight"
12 __email__ = "rob@spot.colorado.edu"
13 __status__ = "Production"
Status should typically be one of "Prototype", "Development", or "Production". maintainer should be the person who will fix bugs and make improvements if imported. credits differs from author in that credits includes people who reported bug fixes, made suggestions, etc. but did not actually write the code.
Comments
Comments should be full sentences, end with a period.
Abbreviations
alignment aln archaeal arch auxillary aux bacterial bact citation cite current curr database db dictionary dict directory dir end of file eof eukaryotic euk frequency freq expected exp index idx input in maximum max minimum min mitochondrial mt number num observed obs original orig output out phylogeny phylo previous prev protein prot record rec reference ref sequence seq standard deviation stdev statistics stats string str structure struct temporary temp taxonomic tax variance var
and
class cls thread th transaction txn deferred dfd format fmt template tmpl implementation impl button btn_* checkbox chk_* middleware *_mw callback cb filename fn file object f
re_ for regular expression strings.
rx_ for compiled regular expressions.
m for matches.
r for return values.
Function calls
Attempt to minimize vertical space, while not compromising readability.
over
over
The latter is acceptable if line 1 or any of the arguments are long. E.g.:
ElementTrees/XML parsing
Use elem for unknown elements.
Prefix 'x' onto elements/trees. E.g. for <body> use xbody, <table> use xtable, etc.
From: http://self.maluke.com/style
Other resources
google/yapf: A formatter for Python files. clang-format-like, similar to gofmt
Lectures
PyCon 2015: Beyond PEP8: Best practices for beautiful intelligible code
Adding an arbitrary line break to make a line <= 80 characters, shortening variable names, etc does NOT make code better.
- "Foolish consistency is the hobgoblin of little minds" — right at the top of PEP8, people read right through it!