On Apr 12, 1:30 pm, Darren Dale <[email protected]> wrote:
> On Apr 11, 2:15 pm, Darren Dale <[email protected]> wrote:
>
>
_
>
> > format1.Group # implementation of group in format1
> > format2.Group # ...
> > Base.DerivedGroup # base implementation of DerivedGroup, not directly
> > useful
> > format1.DerivedGroup = Base.DerivedGroup(format1.Group) # useful
> > format2.DerivedGroup = Base.DerivedGroup(format2.Group) # useful
>
_
>
> class Group1(object):
>
> def origin(self):
> return "Group1"
>
> class Group2(object):
>
> def origin(self):
> return "Group2"
>
> def _SubGroup(superclass):
>
> class SubGroup(superclass):
> pass
>
> return SubGroup
>
> SubGroup = _SubGroup(Group2)
> sub_group = SubGroup()
>
> print sub_group.origin()
You can create new types in one statement:
SubGroup= type( "SubGroup", ( BaseGroup, ), { } )
--
http://mail.python.org/mailman/listinfo/python-list