Skip to main content

Idiomatic APIs with the Python Data Model

Luciano Ramalho (Python.pro.br)
Python
E145
Average rating: ***..
(3.67, 3 ratings)

The Data Model is a description of Python as a framework. The special methods defined in it are called by the Python interpreter to handle your objects in a variety of contexts like:

  • iteration;
  • acessing items in collections using [];
  • attribute access using obj.attr;
  • operator overloading;
  • string representation and formatting;
  • object creation and destruction;
  • managed contexts (i.e. with blocks);

The examples include:

  • iterating over words in text;
  • simple math with multi-dimensional vectors;
  • dynamic attributes to implement the Proxy design pattern;

Most of the techniques apply from Python 2.6 to 3.4. The examples will show Python 3.3 code.

Photo of Luciano Ramalho

Luciano Ramalho

Python.pro.br

Luciano Ramalho was a Web developer before the Netscape IPO in 1995, and switched from Perl to Java to Python in 1998. Since then he worked on some of the largest news portals in Brazil using Python, and taught Python web development in the Brazilian media, banking and government sectors. His speaking credentials include OSCON 2002, and 15 talks over the years at PythonBrasil (the Brazilian PyCon) and FISL (the largest FLOSS conference in the Southern Hemisphere). In 2012 he was a keynote speaker at the RuPy Strongly Dynamic Conference in São José dos Campos, Brazil, and had 2 talks accepted for PyCon USA (to be presented March, 2013). Ramalho is a member of the Python Software Foundation and co-founder of Garoa Hacker Clube, the first hackerspace in Brazil. He is the owner of Oficinas Turing, a training company.