is python Object oriented??

Michael Torrie torriem at gmail.com
Fri Jan 30 15:32:00 EST 2009


Veerendra Ganiger wrote:
> Python is not purely object oriented programming, because we can write
> functions without any class.
> You are right, predefined class attributes are available when we write or
> execute a piece of python code without defining class, that means it's just
> using objects for it's purpose. It does not mean its purely object oriented.

To be clear, python does not force you to lay out your code according to
some strict object-oriented paradigm.  But Python itself is still purely
object-oriented, as is your script when parsed.

This function without a class that you mentioned, is in fact an object
with attributes.  You can pass a function around just like any other
object.  Even calling a function is invoked like so:

myfunc.__call__(params)

So necessitating that code be inside a class has nothing to do with
object-oriented programming.  Let's not forget that classes are
themselves objects (metaobjects in smalltalk parlance if I recall
correctly).

Now python does not have any way besides lambda expressions of creating
unbound function objects, but in practice this doesn't matter as I can
rebind names freely.  I can still do:

a=myfunc
myfunc=some other expression or object

> It all depends on implementation, I think even we can make "C" object
> oriented with proper implementation.

Indeed, any code based on gobject libraries can be object-oriented in
design and function.



More information about the Python-list mailing list