is python Object oriented??

Stephen Hansen apt.shansen at gmail.com
Thu Jan 29 15:27:02 CET 2009


On Thu, Jan 29, 2009 at 5:58 AM, M Kumar <tomanishkb at gmail.com> wrote:

> but still I am not clear of the execution of the code, when we write or
> execute a piece of python code without defining class, predefined class
> attributes are available (not all but __name__ and __doc__ are available).
> does it mean anything to this topic. Is it necessory to have __module__,
> __dict__ and __bases__ for a class object in python?


I think there's some confusion on what you're asking; Python enables you to
write object oriented software if you choose to. It also enables you to
write procedural software if you choose to. There's other paradigms it
supports too, to varying degrees. Its a tool that allows you to use it as
you wish, instead of saying that a paradigm is the Right Way to do it.

When you are writing object oriented software, you generally define classes.
Class can inherit from other classes: if they do then the __bases__
attribute is set on the class itself to indicate which classes it inherits
from.

All Python code is within a module -- as a module is simply a file. For
classes, functions and methods, the __module__ attribute simply points to
which module it was defined in.

The __dict__ of a class represents the dictionary of attributes that are
"in" or "on" that class (approximately).

But those are all implementation details. You don't have to set any of them
or worry about any of them generally.

You just:

class MyClass:
    def __init__(self, bar):
        self.value = bar
    def foo(self):
        return self.value

You don't have to set any class attributes to work with classes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090129/5488f109/attachment.html>


More information about the Python-list mailing list