I have been wondering for a while if there is easier way to assign class attributes to method local namespace. For example, in dosomething method, I explicitly make references to self.a and self.b:
class test:
def __init__(self):
self.a = 10
self.b = 20
def dosomething(self):
a = self.a
b = self.b
return(a + b)
But sometimes I have a lot of variables (more than 10) and it gets messy to type and look at - I would have bunch of var = self.var statements at the beginning of a method.
Is there any way to do this more compact way? (I know updating local() is not a good idea)
Edit: Ideally, what I want is:
def dosomething(self):
populate_local_namespace('a', 'b')
return(a + b)
dosomethingmethod that looks like "return (self.a + self.b)"? What benefit do you expect to get from this?self.'s make expressions very long and ugly.