how fast is object-oriented Python code?

beliavsky at aol.com beliavsky at aol.com
Thu Mar 4 10:59:05 EST 2004


I am reading about object-oriented programming in "Learning Python",
2nd. ed. by Lutz and Ascher. On p299, they write

"... most of the OOP story in Python boils down to the expression
object.attribute. [...] In fact, when classes are involved, the Python
expression above translates to the following in natural language:
'Find the first occurrence of attribute by looking in an object, and
all classes above it, from bottom to top and left to right'"

It seems to me that doing this in a scripting language, at run-time,
could be slow, compared to an equivalent code not using classes. How
fast is Python OO code compared to non-OO code?

I know that object-oriented numerical code in C++ can be much slower
than the procedural C or Fortran equivalent, unless one is careful. To
what extent is this true with OO and non-OO Python?



More information about the Python-list mailing list