the 'in' operator and class instances

Vinoo vasudevan ee01b092 at ee.iitm.ernet.in
Sun Jun 8 22:28:41 EDT 2003


Hi,
 Thanks all for replying to this question. Just a few comments. As for as the
GeometricShape example is concerned that class has to implement __contains__
anyway, so this would override the default behaviour namely memebership
testing w/o any problems. 
 The fact that redefining __contains__ would mean we lose the ability to use
'in' to check for membership and would have to fall back on hasattr(..) means
this ain't a good idea. Thanks for pointing this out. My reason for asking
this question is cos I thought it would make the syntax a little more
convenient. As a newbie after using 'in' with nearly all the basic types it
just felt "logical" :-) to write "... if member in instance: ... ". 

Vinoo

P.S. Sorry I can't enclose the previous mails in this thread as I deleted them
by mistake.






More information about the Python-list mailing list