<br><div class="gmail_quote">On Thu, Jan 29, 2009 at 5:58 AM, M Kumar <span dir="ltr"><<a href="mailto:tomanishkb@gmail.com">tomanishkb@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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?</blockquote>
</div><br>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.<br>
<br>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.<br>
<br>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. <br><br>The __dict__ of a class represents the dictionary of attributes that are "in" or "on" that class (approximately).<br>
<br>But those are all implementation details. You don't have to set any of them or worry about any of them generally.<br><br>You just:<br><br>class MyClass:<br> def __init__(self, bar):<br> self.value = bar<br>
def foo(self):<br> return self.value<br><br>You don't have to set any class attributes to work with classes. <br>