INdT projects tries to follow:

 http://www.python.org/dev/peps/pep-0008/

We also use other conventions:

Naming

  • Attributes and methods should be in lowercase, separating names by underscore (avoid camelCase).
  • Class names should start with a uppercase letter in CamelCase.

Private members

  • Private variables and functions should have identifier started with underline
class A:
    def __init__(self, name, parent):
        self._name = name
        self._parent = parent

    def get_name(self):
        return self._name

    def get_parent(self):
        return self._parent

Getters and setters

  • Getters follow the pattern: get_value()
  • Setters follow the pattern: set_value()
  • When a variable has getter and setter that just change it's value and nothing more, it's recommended to just declare it as public (without underline).
class A:
    def __init__(self):
        self._pos = (0, 0) # private
        self.color = "#FFFFFF" # public

    def get_pos(self):
        return self._pos

    def set_pos(self, value):
        self._pos = value
        self.recalculate()

    pos = property(get_pos, set_pos)

    ...