issubclass funny business

Gordon McMillan gmcm at hypernet.com
Tue Apr 11 18:23:22 CEST 2000


Les Schaffer wrote:

> I have the following class hierarchy:
> 
> ------ in module FileScanner -----
> 
> class StandardArrayFileScanner(ArrayFileScanner):
> 
> --------- in module cie ----------
> 
> from FileScanner import StandardArrayFileScanner
> 
> class CIE_Standards(StandardArrayFileScanner):
> ...    
> 
> class Photopic(CIE_Standards):
> ...
> 
> class CIE(CIE_Standards):
> ...
> 
> 
> but when i need to test whther an object is an instance of a subclass
> of StandardArrayFileScanner:
> 
>         # make sure std is of the correct type
>         if not issubclass(std.__class__, StandardArrayFileScanner):
>             import cie
>             print std.__class__, cie.CIE.__bases__
> 	    raise NotStandardArrayError
> 
> 
> but it doesnt work, even though std is of type cie.CIE :
> 
> (gustav)~/Engineering/dspring/stoplite/matlab/Jue-Data/: python FileScanner.py

You are running FileScanner. Therefore, in FileScanner, class 
StandardArrayFileScanner is defined in __main__. If you 
trickle up to the top of __bases__ above, you'll find 
FileScanner.StandardArrayFileScanner, which is not the same 
object. At least, that's my guess at what's going on.
 
> cie.CIE (<class cie.CIE_Standards at 813b320>,)  <=== result of print stmt
> 
> huh??????


- Gordon




More information about the Python-list mailing list