"Roelof Wobben" <rwob...@hotmail.com> wrote
I guess the question to ask/consider is: How can be establish
whether a
particular object supports a particular interface/set of
behaviours
In general we "try" it and handle the exceptions
that we require? E.g. how do we most pythonically check whether
some
object "walks like a list" and "quacks like a list" without tying
such
code to explicit type checking?
But the risk is that although it may quack, it does so like a missile
launch program rather than a list - oops! :-)
With the knowlegde I have from the few chapters of thinking like
a computer scientist I don't know the answer to the last question.
If you do need to avoid accidentally launching missiles then you need
to do some type checking - although ideally using isinstance() instead
of type(). But in the majority of cases some sensible documentation
and Python's culture that we are all adults here usually means you
don't
need to.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor