I'm doing some editing recently & normally when I wanted to save time I'd wrap a function around a more generic function. I'm also reading more on OO maintenance and they state I shouldn't be letting an object know the name of another object. I am using functions in the the following:
def getWidth(self, width_id):
retrieve_characteristics(self, variable_id, variable_characteristic)
try: return self.c.fetchone()[0]
except: return None
def retrieve_characteristics(self, variable_id, variable_characteristic):
self.c.execute('SELECT ' + variable_characteristic+ ' FROM ' + variable_characteristic+ ' WHERE id=?',(variable_id,))
My question being - does this apply to functions like this or is there a better way of implementing dry? I have 4 other functions in my base python init which would be using retrieve_characteristics.
Bonus points if anyone has comments on if I can shove the try & except code into the retrieve_characteristics without weird inherent errors later :)
Thanks!