PEP: Specialization Syntax

Kay Schluehr kay.schluehr at gmx.net
Mon Aug 8 02:08:15 EDT 2005


Nicolas Fleury wrote:

> It is necessary to maintain a
> dictionary of types (to avoid redundacy) and simple things like:
>
> def makeType(someArgument):
>      class MyObject:
>          someArgument = someArgument
>      return MyObject
>
> are not allowed.

def makeClass(cls_name, **kw):
    return type(cls_name,(), kw)

>>> MyObject = makeClass("MyObject",a=8)
>>> MyObject
<class '__main__.MyObject'>

>>> MyObject.a
8

Regards,
Kay




More information about the Python-list mailing list