Apr 11, 2015 python

PEP8 is the most important guide for coding standard in Python. There are also other coding practices that improve readability and maintenance.

Raymond Hettinger’s “Beyond PEP 8” from PyCon 2015 (Youtube)

This was an excellent talk regarding the python style guide and the focus on what really matters instead of just PEP8.

Summary:

Elements of Python Style

Using reST for docstring

Example

# From https://github.com/kennethreitz/requests/blob/master/requests/api.py
def get(url, params=None, **kwargs):
    """Sends a GET request.
    :param url: URL for the new :class:`Request` object.
    :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
    :param \*\*kwargs: Optional arguments that ``request`` takes.
    :return: :class:`Response <Response>` object
    :rtype: requests.Response
    """

    kwargs.setdefault('allow_redirects', True)
    return request('get', url, params=params, **kwargs)