Product SiteDocumentation Site

Chapter 3. Python Coding Guidelines

Table of Contents

3.1. Python Boilerplate
3.2. Python Compatibility
3.2.1. Python Future Imports
3.2.2. Other Python Compatibility Requirements
3.2.3. Python Usages to Avoid
3.3. Formatting Python Code

3.1. Python Boilerplate

Every Python file should start like this:
[<SHEBANG>]
""" <BRIEF-DESCRIPTION>
"""

# Pacemaker targets compatibility with Python 2.6+ and 3.2+
from __future__ import print_function, unicode_literals, absolute_import, division

__copyright__ = "Copyright (C) <YYYY[-YYYY]> Andrew Beekhof <andrew@beekhof.net>"
__license__ = "<LICENSE> WITHOUT ANY WARRANTY"
If the file is meant to be directly executed, the first line (<SHEBANG>) should be #!/usr/bin/python. If it is meant to be imported, omit this line.
<BRIEF-DESCRIPTION> is obviously a brief description of the file’s purpose. The string may contain any other information typically used in a Python file docstring.
The import statement is discussed further in Section 3.2.1, “Python Future Imports”.
<YYYY> is the year the code was originally created (it is the most important date for copyright purposes, as it establishes priority and the point from which expiration is calculated). If the code is modified in later years, add -YYYY with the most recent year of modification.
<LICENSE> should follow the policy set forth in the COPYING file, generally one of "GNU General Public License version 2 or later (GPLv2+)" or "GNU Lesser General Public License version 2.1 or later (LGPLv2.1+)".