On Wed, Dec 18, 2013 at 5:40 AM, spir <[email protected]> wrote:
> C.__setattr__(C, "baz", "BAZ")
> which fails, for any reason, with
> TypeError: can't apply this __setattr__ to type object
You need __setattr__ from the metaclass:
>>> class C: pass
...
>>> type(C).__setattr__(C, "baz", "BAZ")
>>> C.baz
'BAZ'
You can bind the method like this:
>>> C_setattr = type(C).__setattr__.__get__(C)
>>> C_setattr('foo', 'bar')
>>> C.foo
'bar'
But just use built-in setattr(), really.
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor