Ok I have some code that boils down to a pattern like this
class Foo(object):
def get_something1(self):
# in the actual code it asks a web server but here I replaced that with "foo_something1" instead of the code from a web server
self.something1 = "foo_something1"
def get_something2(self):
# needs the result of get_something1; right now I have it get it by instance variable like so
self.something2 = self.something1 + "_something_2"
My question is, should I do the above (methods getting what they need by instance variables) or by taking arguments like so; also should I return something1 and something2 in the get_* methods?
class Foo(object):
def get_something1(self):
# in the actual code it asks a web server but here I replaced that with "foo_something1" instead of the code from a web server
self.something1 = "foo_something1"
def get_something2(self, something_1):
# needs the result of get_something1; right now I have it get it by instance variable like so
self.something2 = something1 + "_something_2"
Now in my code the methods return deferreds (twisted); Right now when the deferreds fire it sets the instance variables and returns None; In the actual code I have another function that checks to see if something1 or something2 is expired; I update them which brings up a problem because I update it like so...
d = self.get_something1()
##d.addCallback(self.get_something2) # errors because it gets the argument None (so I do below)
d.addCallback(lambda ignored: self.get_something2())# problem the deferred for get_something2 is inaccessible
So right now the update code is either ugly, error filled, or both. So I have a feeling that I am doing something either a) un pythonic or b) un twisted or c) some other bad design.
Thanks for the answers, but those won't work because the functions return deferreds and not the actual value (other wise it would have to block).