For different classes I have different settings (ex: addresses) for a shared object s. I have to reinforce the address variable s.addr every time the method is called since class ItemA and ItemB to to set s.addr to different addresses. Is there a way to simplify this redundancy?
Ex:
class ItemA:
def __init__(self,s,addr):
self.s = s
self.addr = addr
def a(self,addr):
self.s.addr=self.addr # anyway to remove this line that exist in every method
self.s.run_a()
def b(self,addr):
self.s.addr=self.addr #
self.s.run_b()
class ItemB:
def __init__(self,s,addr): # take same s as ItemA
self.s = s
self.addr = addr
def a(self,addr):
self.s.addr=self.addr #
self.s.run_a()
def c(self,addr):
self.s.addr=self.addr #
self.s.run_c()
ItemsA, B are called randomly so address needs to be update in every method.
A=ItemA(s,9) # object s, address 9
B=ItemB(s,7) # same object s, but use address 7
A.a()
B.a()
B.c()
A.b()
For extra info, it is to control instruments with GPIB and each of them has different address. s is pexepect that send generic command to the address specified in s.addr . But interested in more general python question.