Home › Curriculum › Technical Foundations › Python essentials
Python for Odoo · 16 min · Python 3.12Python essentials
Values, types, strings, lists, dicts, sets, control flow, functions and exceptions: the Python you'll read in every Odoo module.
In this lesson
- Types and collections
- Control flow and functions
- Exceptions, and the ones Odoo raises
Key points
- dicts drive create/write values and context
- Recordsets are iterable: for order in orders:
- *args/**kwargs appear when overriding methods
- UserError, ValidationError, AccessError, MissingError
Real-world example
A techno-functional consultant read a traceback ending in KeyError: 'discount' in a custom module. The code did vals['discount'] when the dict didn't always contain it. Changing it to vals.get('discount', 0.0) fixed a crash that had blocked a client's order imports for a day.
Questions and answers
What's the difference between a list and a tuple?
Lists are mutable; tuples are immutable.
How do you make a message translatable in Odoo?
Wrap it in _() imported from odoo (or self.env._ in recent versions).