Re: A problem with classes - derived type

2016-05-09 Thread Paulo da Silva
Às 05:20 de 09-05-2016, Paulo da Silva escreveu: Thank you Yann and Peter. I really didn't know anything about those "things". So far I have worked a lot with classes but they are written by me. Now I needed to derive pandas.Series (for example) and it has some methods that return pandas.Series o

Re: A problem with classes - derived type

2016-05-09 Thread Peter Otten
Paulo da Silva wrote: > Hi! > > Suppose I have a class A whose implementation I don't know about. > That class A has a method f that returns a A object. > > class A: > ... > def f(self, <...>): > ... > > Now I want to write B derived from A with method f1. I want f1 to return > a B object: > >

Re: A problem with classes - derived type

2016-05-08 Thread Yann Kaiser
If you can't change A to use something like "type(self)(...)" to create its return value, you could use the dark side and swap res's __class__: res.__class__ = B Or: res.__class__ = type(self) Do note that B.__init__ will not be run when you do this, so it is up to you to execute any ad

A problem with classes - derived type

2016-05-08 Thread Paulo da Silva
Hi! Suppose I have a class A whose implementation I don't know about. That class A has a method f that returns a A object. class A: ... def f(self, <...>): ... Now I want to write B derived from A with method f1. I want f1 to return a B object: class B(A):

Re: problem with classes

2005-08-26 Thread bruno modulix
cfgauss wrote: > I am having a strange problem with classes. I'm fairly sure the > problem is with classes, anyway, because when I re-write the program > without them, it works like I'd expect it to. > > When I run this program, at first, L[0].z[1] is 0, because z=[0,0

problem with classes

2005-08-26 Thread cfgauss
I am having a strange problem with classes. I'm fairly sure the problem is with classes, anyway, because when I re-write the program without them, it works like I'd expect it to. When I run this program, at first, L[0].z[1] is 0, because z=[0,0]. But after I run that loop to assign