[PyQt] question about dip models and dip io

Darren Dale dsdale24 at gmail.com
Thu Aug 5 16:49:23 BST 2010


On Thu, Aug 5, 2010 at 10:59 AM, Phil Thompson
<phil at riverbankcomputing.com> wrote:
> On Thu, 5 Aug 2010 10:13:27 -0400, Darren Dale <dsdale24 at gmail.com> wrote:

[...]

>> Is there any documentation available on dynamically creating a new model
>> type?
>
> You do it just like you would for any other Python type by calling its
> meta-type...
>
> from dip.model import MetaModel, Model, Int
>
> my_dynamic_type = MetaModel('MyDynamicType', (Model, ),
> dict(my_int_attr=Int))
>
> my_instance = my_dynamic_type(my_int_attr=10)
>
> # This will raise an exception...
> my_instance.my_int_attr = 'bad'
>
> You will have to use the current dip snapshot as I hadn't exposed
> MetaModel as part of the dip.model in v0.1.

Great, thank you!


More information about the PyQt mailing list