Python dynamic attribute creation

Stephen Hansen me+list/python at ixokai.io
Fri Jun 25 12:52:21 EDT 2010


On Fri, Jun 25, 2010 at 6:15 AM, WANG Cong <xiyou.wangcong at gmail.com> wrote:

> 4) Also, this will _somewhat_ violate the OOP princples, in OOP,
> this is and should be implemented by inherence.
>

Others have answered the rest fine, I just wanted to add: Who says we have
to follow OOP principles, huh?

If you want to follow OOP principles: Python will do absolutely nothing to
stop you! All power to you.

You're also free to break the principles if you choose to: this is the key
point. Python lets you choose to. If you firmly believe in the principles,
you can embrace them fully by simply never choosing to violate them in any
way.

Some languages force you to adopt the OOP paradigm and build its principles
directly into the language. Python does not. A python "object" is not,
necessarily, the same thing as an abstract Object in the OOP world. But you
can use it as such an object if you want and do everything OOP needs, though
some things (such as encapsulation) are done by convention more then a
strict enforcement by the language.

Or you can use it and abuse it and do some really interesting and slightly
crazy things as you experiment with other paradigms (even some lesser known
ones), perhaps inventing a new paradigm all together. :)

Most of my code is pretty OOPish. But I have more then a few places where I
dig out my metaclass dark magic and transform objects into some distinctly
unique tool.

Python's content with letting me do that. Not that I'd show anyone or admit
to my vices publicly, though. :)

--S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100625/6881ad4c/attachment.html>


More information about the Python-list mailing list