The Python Object Model

OR
The Python Data Model

Everything is Data

Everything is data is data

Everything is data is data is data

You know where this is going

You know where this is going is

wait for it...

Everything is data is data is data is data

Data

Interpreters

  • Data is 'meaningless' without some kind of system that it means something to
  • In CS, we have the Turing Machine (bless his soul)
  • Machines are models  that understand a particular kind of data - specified by a formal grammar and can operate on this 'correct' data

But what is meaning?

The Turing Machine

  • Daniel, don't spend time talking about the Turing machine

Python

So Python is one of such (not so) abstract machines that accepts a strictly defined grammar (what we call syntax) and has a set of instructions it applies to data that conforms to this grammar.

>>> 2 + 2
4

>>> def freedom():
        print(42)

>>> def 1984
SyntaxError: invalid syntax

The Python Object Model

Objects are Python’s abstraction for data.

Every object has an identity, a type and a value.

The value of some objects can change. Objects whose value can change are said to be mutable; objects whose value is unchangeable once they are created are called immutable.

An object’s type determines the operations that the object supports.

Objects are never explicitly destroyed; however, when they become unreachable they may be garbage-collected.

The Python Object Model

All data in a Python program is represented by objects or by relations between objects. 

Special Methods

__init__
__del__
__repr__
__str__
__bytes__
__bool__
__getattr__
__add__
__mul__

In this talk, we are going to focus on Python's "magic" methods that give us access to built-in operations.

Special Methods

Special Methods

Code Lab

        git clone https://github.com/letroot/object-model.git

The Python Object Model

By Daniel Adeyemo

The Python Object Model

He was too sleepy to fill in a description that night, something about Python and objects I think.

  • 60