Post by Trent RigsbeeHi! I'm on the version 2.4, going through Beginning Python (Wrox), and
menu_specials._contains_("test")
Any ideas on what I'm doing wrong? Thanks!
It looks like you may be reading the wrong book!
Why they would suggest you ever execute that code I have no idea,
using the has_key() method is the normal way to do that.
However, if you really want to call contains() it has two underscores on
each side.
This is a standard Python idiom for naming functions which you are *not*
expected to call directly. Occasionally you do need to do so but never
as a beginner! Hence why is "Beginning Python" even telling you about them?
The purpose of the __contains__ () function is to allow you to modify the
behaviour of the has_key() method (which does call __contains__() ) should
you define your own dictionary type, you should not have to call it
directly.
HTH,
Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld