Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Python Style Guide

This page contains guidelines for Python source code for the Paparazzi project.

PEP8 is the de-facto code style guide for Python and covers the most important aspects.

There exists a command-line program, pep8, that can check your code for conformance.

Formatting Guide

  • Use 4 spaces per indentation level, do NOT use tabs.
  • Remove any trailing white space at the end of lines.
  • Use Unix line endings ('\n'); do NOT use DOS endings ('\r\n')

Python 2 and 3 compatibility

Try to write python code so that it works with python2 (>=2.6) and python3. See e.g. supporting Python 2 and 3 without 2to3 conversion for details.

The most common things to keep in mind:

  • Use the print() function not the statement with
    from __future__ import print_function
  • Beware of integer division, use
    from __future__ import division

Basic example:

from __future__ import print_function
from __future__ import division
def halve_example(x, y=2):
"""Example function to show division."""
return x / y
if foo == "bar":
halve_example(x, y)
except ZeroDivisionError as detail:
print("Ups...", detail)