Trent Rigsbee wrote:
> Hi! I'm on the version 2.4, going through Beginning Python (Wrox),  and I'm 
> getting the above error. I'm trying to do this:
> 
> menu_specials._contains_("test")
> 
> Any ideas on what I'm doing wrong? Thanks!

The name of the method is __contains__ (note *double* leading and trailing 
underscores). But you normally shouldn't call this directly, you should write
  "test" in menu_specials
instead.

In general the methods and atttributes whose names start and end with double 
underscores are special to the language (in fact they are called 'special 
methods') and they are rarely called by code you write. They are hooks that let 
the author of a class define its behaviour. In this case, the __contains__() 
method is created to define how a dict object tests for membership.

Kent

-- 
http://www.kentsjohnson.com

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to