Automatically generating arithmetic operations for a subclass

andrew cooke andrew at acooke.org
Tue Apr 14 16:32:30 CEST 2009


Arnaud Delobelle wrote:
> "andrew cooke" <andrew at acooke.org> writes:
>> Arnaud Delobelle wrote:
>>> class MyInt(int):
>>>       for op in binops:
>>>           exec binop_meth % (op, op)
>>>       for op in unops:
>>>           exec unop_meth % (op, op)
>>>       del op
>>
>> what's the "del" for?
>
> Without it, 'op' would end up as a class attribute.

ah!  ok, that makes sense, i guess.  thanks.

(i just tried it out and you're right, of course, but also if binops and
unops are empty you get an error, although i guess that's no an issue
here).

andrew





More information about the Python-list mailing list