return an object of a different class

spam at uce.gov spam at uce.gov
Wed Feb 16 01:56:06 EST 2011


>> I didn't explain my problem, chose a terrible example. This is more
>> what I'm trying to do:

Basically the subclass I want to use is based on some of the data I extract 
from a blob of data. If I use a function to extract the data before I create 
the objects, then I need to do a bunch of assignments afterwards.

>
> Unfortunately, it's still very contrived, and the names don't give any
> suggestion as to what you're trying to achieve. Can you improve on that?
>
>> class ThingyTypeA:
>>    def __init__(self):
>>      # do some further extraction specific to type A
>>      further_extract()
>>
>>
>> class ThingyTypeB:
>>    def __init__(self):
>>      # do some further extraction specific to type B
>>      further_extract()
>
> Perhaps you want those classes to inherit from your base class. Have you
> done the Python tutorial? It covers inheritance and how to use it.

Yes, I have done subclasing before, and yes ThingyTypeA and B should be 
subclassing Thingy



-- 
Yves.                                                  http://www.SollerS.ca/
                                                        http://blog.zioup.org/



More information about the Python-list mailing list