class dataWriter(object):
def __init__(self, data): self.data = data #main function def write(self):
#if contains this data, execute the corresponding writing function for category,value in self.data.items(): self.__getattribute__('write'+category)(value)
def writeA(self, A): print('A: ' + str(A))
def writeB(self, B): print('B: ' + str(B))
def writeC(self, C): print('C: '+ str(C))
a = dataWriter(data={'A':100, 'B': 10}) a.write() ##result #A: 100 #B: 10 |
No comments:
Post a Comment