Difference between revisions of "Python"

From mn/geo/geoit
Jump to: navigation, search
Line 4: Line 4:
  
 
Let's start with some 'best practices' for programming with Python. First and foremost, one should become familiar with the [http://www.python.org/dev/peps/pep-0008/ PEP8]. This is a 'Python Enhancement Proposal' (PEP). In Python this is the equivalent of a detailed featured request. [http://www.python.org/dev/peps/pep-0008/ PEP8] lays the foundation for how you should format your code.
 
Let's start with some 'best practices' for programming with Python. First and foremost, one should become familiar with the [http://www.python.org/dev/peps/pep-0008/ PEP8]. This is a 'Python Enhancement Proposal' (PEP). In Python this is the equivalent of a detailed featured request. [http://www.python.org/dev/peps/pep-0008/ PEP8] lays the foundation for how you should format your code.
 +
 +
One important feature of python to highlight are Documentation Strings::
 +
 +
    Conventions for writing good documentation strings (a.k.a. "docstrings")
 +
    are immortalized in PEP 257 [3].
 +
 +
    - Write docstrings for all public modules, functions, classes, and
 +
      methods.  Docstrings are not necessary for non-public methods, but you
 +
      should have a comment that describes what the method does.  This comment
 +
      should appear after the "def" line.
 +
 +
    - PEP 257 describes good docstring conventions.  Note that most
 +
      importantly, the """ that ends a multiline docstring should be on a line
 +
      by itself, and preferably preceded by a blank line, e.g.:
 +
 +
      """Return a foobang
 +
 +
      Optional plotz says to frobnicate the bizbaz first.
 +
 +
      """
 +
 +
    - For one liner docstrings, it's okay to keep the closing """ on the same
 +
      line.
 +
 +
  
  

Revision as of 13:13, 14 September 2011

The Python programming language is a powerful language which has gained popularity over the past several years. It is widely used in the scientific community, and there are numerous tools readily available for common data analysis tasks. At NILU there is a repository for Modules developed internally. The pages herein provide important information on working with Python on the NILU servers and also with your own PC.

Best Practices

Let's start with some 'best practices' for programming with Python. First and foremost, one should become familiar with the PEP8. This is a 'Python Enhancement Proposal' (PEP). In Python this is the equivalent of a detailed featured request. PEP8 lays the foundation for how you should format your code.

One important feature of python to highlight are Documentation Strings::

   Conventions for writing good documentation strings (a.k.a. "docstrings")
   are immortalized in PEP 257 [3].
   - Write docstrings for all public modules, functions, classes, and
     methods.  Docstrings are not necessary for non-public methods, but you
     should have a comment that describes what the method does.  This comment
     should appear after the "def" line.
   - PEP 257 describes good docstring conventions.  Note that most
     importantly, the """ that ends a multiline docstring should be on a line
     by itself, and preferably preceded by a blank line, e.g.:
     """Return a foobang
     Optional plotz says to frobnicate the bizbaz first.
     """
   - For one liner docstrings, it's okay to keep the closing """ on the same
     line.




Sub Page

<subpages />