Thank you so much all, DayDreamer,Justinc as always!
I am lucky enough to learn about the __slots__ too!

Matthew,


On Sat, Sep 14, 2013 at 10:33 PM, Justin Israel <[email protected]>wrote:

> I was going to suggest slots as well when I first started reading the
> question, but it appeared Matthew wanted to be able to protect existing API
> from being replaced. Slots would still allow the defined attributes to be
> assigned to, while preventing any new api from being added.
>
>
>
> On Sun, Sep 15, 2013 at 5:15 PM, DayDreamer <[email protected]>wrote:
>
>> Hi, you can use __slots__ in python class, which offically do
>> optimization (masking and sort of memory management )as it will only allow
>> attributes with certain names for the class.
>>
>> Eg.
>>
>> class Foo:
>>     __slots__ = ['a', 'b']
>>     def __init__(self, n):
>>         self.a = n
>>
>> bar = Foo('py')
>> print bar.a # py
>>
>> bar.pretty = 4    # Throws exception.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Python Programming for Autodesk Maya" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to