Python Scalability

Alex alex at somewhere.round.here
Sun May 23 18:05:33 EDT 1999


> What I'm really interested in is whether a given function or object
> supports a specified interface: e.g., I can safely call obj.m(1, 2)
> and get a list object back (or an exception).

I don't know how much this will help you -- from your post, it seems
like there are times when you should have added the method to a class,
and you're getting an error because you failed to.  But you can check
whether a class instance has a certain method using something like

import types

def primma_donna_function (dubious_instance):
    if (not hasttr (dubious_instance, 'method_name')) or \
    	type (dubious_instance.method_name) != types.MethodType:
    	raise 'What am I supposed to do with this incompetent \n' + \
    	      'class instance?  Morons!  All they send me are \n' + \
    	      'morons!'
    
I'm hopelessly unqualified to talk about design issues, but the fact
that you have to go through adding the same method to lots and lots of
different functions suggests to me that you're not using inheritance
effectively in your program's design.

See you.
Alex.




More information about the Python-list mailing list