<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div>Dear all,<br><br>I have what will probably sound as stupid questions for experienced Python users... which I am not, hence my seeking for some help.<br><br>------------<br>QUESTION 1:<br>I've implemeted a class which defines a container with 2 lists of data (with some specific format).<br>Some of the methods simply transform these data and therefore return a new container of 2 lists.<br>I want to be able to use these results without having to re-instanciate them, so I return them as instances of the class:<br><br>class MyClass:<br>    def __init__(self, data):<br>        #various checks for the format and content of data (data = [x,y] where x and y are 2 lists of floats)<br>        self.data = data<br>   
     <br>    def transformdata(self):<br>        newdata = transform(data)<br>        return MyClass(newdata)<br><br>In this way I can do:<br><br>x = list1<br>y = list2<br>data = MyClass([x,y])<br>moddata = data.transformdata()<br>moddata2 = moddata.transformdata()<br><br>Is that the correct way to go (i.e. is this pythonic) ? What I want to avoid is:<br><br>moddata = data.transformdata()<br>moddata2 = MyClass(moddata).transformdata()<br><br>------------<br>QUESTION 2:<br>If I go this way, I have a second problem: if I create a new class which inherits from the previous, I would expect/like the methods from the initial class to return instances from the new class:<br><br>class MyClass2(MyClass):<br><br>    def othermethods(self):<br>        return MyClass2(whatever)<br><br>Then I get:<br><br>x = list1<br>
y = list2<br>
data = MyClass2([x,y])<br>
finaldata = data.transformdata()<br><br>My problem is that finaldata is (of course) an instance of MyClass and not MyClass2. How do I deal with this ?<br><br>All help will be much appreciated...<br><br>Cheers,<br><br>Auré<br>
<br><br></div>
</div><br>




      </body></html>