Testing methods

Cameron Laird claird at lairds.com
Mon Apr 21 17:07:20 CEST 2003

In article <Zohoa.37253$LB6.847098 at news1.tin.it>,
Alex Martelli  <aleax at aleax.it> wrote:
>Anton Muhin wrote:
>   ...
>> try:
>>      foo.absent_method()
>> except (AttributeError, TypeError), e:
>>      print "Failed. Message @%s@" % e, "Type: %s" % e.__class__.__name__
>> else:
>>      print "OK"
>Careful!!!  There's a LITTLE trap here.  If foo DOES have absent_method
>BUT that method's body propagates one of these exceptions, this will
>catch the propagated exception AS IF it had been generated in the attempt
>to access / call it.  You can split the access-and-call in two to help:
>    bound = foo_absent_method
		[important stuff
		on related topics]
  bound = foo.absent_method
is what Alex intended to write, I believe.

Typographical errors rarely merit follow-up--and Alex certainly
commits very, very few of them.  As the original poster described
himself as a beginner, I suspect there might be value in this case
in swift correction.

Cameron Laird <Cameron at Lairds.com>
Business:  http://www.Phaseit.net
Personal:  http://phaseit.net/claird/home.html

More information about the Python-list mailing list