Modifying an instance attribue before returning it /u/joseph_fourier Python Education

Hi /r/learnpython

I’m not sure this is possible, but it would be super useful if I could modify an instance attibute before I return it, i.e.:

class MyClass(object): def method(self, x): self.x = x def process(self): return self.x + 1 def <?>(self): return self.process() >>> m = MyClass() >>> m.method(1) >>> m.x 2 

I had thought to replace <?> with __x__, but that doesn’t work. Calling that method directly with m.__x__() does work (ofc.).

As stated, this might not be possible but it would be really useful if it was. I’m really doing a data modelling problem and I’d like to return some stored data as dataframe rather than what my class stores the data as internally.

Thanks!

submitted by /u/joseph_fourier
[link] [comments]

​r/learnpython Hi /r/learnpython I’m not sure this is possible, but it would be super useful if I could modify an instance attibute before I return it, i.e.: class MyClass(object): def method(self, x): self.x = x def process(self): return self.x + 1 def <?>(self): return self.process() >>> m = MyClass() >>> m.method(1) >>> m.x 2 I had thought to replace <?> with __x__, but that doesn’t work. Calling that method directly with m.__x__() does work (ofc.). As stated, this might not be possible but it would be really useful if it was. I’m really doing a data modelling problem and I’d like to return some stored data as dataframe rather than what my class stores the data as internally. Thanks! submitted by /u/joseph_fourier [link] [comments] 

Hi /r/learnpython

I’m not sure this is possible, but it would be super useful if I could modify an instance attibute before I return it, i.e.:

class MyClass(object): def method(self, x): self.x = x def process(self): return self.x + 1 def <?>(self): return self.process() >>> m = MyClass() >>> m.method(1) >>> m.x 2 

I had thought to replace <?> with __x__, but that doesn’t work. Calling that method directly with m.__x__() does work (ofc.).

As stated, this might not be possible but it would be really useful if it was. I’m really doing a data modelling problem and I’d like to return some stored data as dataframe rather than what my class stores the data as internally.

Thanks!

submitted by /u/joseph_fourier
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *