Magic?

Miles semanticist at gmail.com
Sun Jul 13 17:33:37 EDT 2008


On Sun, Jul 13, 2008 at 12:55 PM, mk <mrkafk at gmail.com> wrote:
> So my updated question is where does this lstr() instance keep the original
> value ('abcdef')? It obviously has smth to do with inheriting after str
> class, but I don't get the details of the mechanism.

Through the str.__new__ method: http://docs.python.org/ref/customization.html

Calling a constructor:
foo = Foo(1, 2, 3)

Is roughly equivalent to:
foo = Foo.__new__(Foo, 1, 2, 3)
Foo.__init__(foo, 1, 2, 3)

As a side note, you may already know this, but it's not necessary to
create a property setter that raises an error to make a property
read-only; you can simply not define a setter method.

-Miles



More information about the Python-list mailing list