metaclasses for type comparison

David C. Fox davidcfox at post.harvard.edu
Wed Sep 10 23:03:02 EDT 2003


Simon Burton wrote:
> In today's experiment, I was wondering if I could make the comparison
> operators (<,<=,>=,>) work on classes (types) according to inheritance.
> 
> The idea is, for example, classes lower in the class hierarchy would be
> less than (more specialized) than classes they inherit from.
> 
> class A(object):
>   pass
> 
> class B(A):
>   pass
> 
> B < A # should be True

Is this an exercise to help you learn about metaclasses, or do you 
actually want to be able to check whether B is a subclass of A.  If the 
latter, then try issubclass(B, A).  Otherwise, ignore this comment

David





More information about the Python-list mailing list