How to copy a ClassObject?
Karlo Lozovina
_karlo_ at _mosor.net_
Wed Mar 21 14:54:39 EDT 2007
Duncan Booth <duncan.booth at invalid.invalid> wrote in
news:Xns98F995B5964F6duncanbooth at 127.0.0.1:
> Consider yourself corrected.
>
> You could do what you are attempting with:
>
> tmp = new.classobj('tmp', First.__bases__, dict(First.__dict__))
>
> which creates a new class named 'tmp' with the same base classes and
> a copy of First's __dict__ except that the __name__ attribute for the
> new class will be set to 'tmp'. The attribute values are still shared
> between the classes (which is significant only if they are mutable),
> but otherwise they won't be sharing state.
> I have no idea why you would want to do this, nor even why you would
> want a 'name' attribute when Python already gives you '__name__'.
First of all, thanks for a clarification. 'name' attribute was just a
(dumb) example, it was the first thing to come to mind.
The idea behind all of this was to create classes dynamicaly, without
knowing in advance their names, or base class(es). So I figured I'd just
copy the base class and modify the attributes.
Instead, this way of subclassing seems to work just right for my purposes.
--
_______ Karlo Lozovina - Mosor
| | |.-----.-----. web: http://www.mosor.net || ICQ#: 10667163
| || _ | _ | Parce mihi domine quia Dalmata sum.
|__|_|__||_____|_____|
More information about the Python-list
mailing list