check type when assignment
Bruno Desthuilliers
onurb at xiludom.gro
Wed Jul 12 12:20:11 EDT 2006
Diez B. Roggisch wrote:
> pipehappy wrote:
>
>
>>Hello everyone:
>>
>>Is there a way to check the type when do assignment?
>>
>>if I write:
>>ab = bc
>>and want to make sure the return value of isinstance(bc, klass) is True
>>or I will raise
>>a exception.
>
>
> In general, not doable. The assignment operator is not overloadable.
>
> Only if you use assignments of the form
>
> a.foo = bar
>
> you could overwrite the __setattribute__-method
(Or use a Descriptor)
> to achieve what you want.
>
> Diez
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list
mailing list