I'm not sure if I'm asking this correctly, but I know you all are smart enough to figure it out :). I am having trouble condensing some repetitive code in a few python classes. Here is an example of what I mean...
class Parent:
PATH_PROPERTIES = [ 'parent' ]
def __init__(self, path):
self.props = { 'parent': path }
def getPath(self):
return self.props['parent']
class Child(Parent):
PATH_PROPERTIES = [ 'child' ]
def __init__(self, path):
self.props = { 'child': path }
def getPath(self):
return self.props['child']
Above, is the current situation, but I would like to reduce some of the duplication by doing something like...
class Parent:
name = 'parent'
PATH_PROPERTIES = [ name ]
def __init__(self, path):
self.props = ( name: path)
def getPath(self):
return self.props[name]
The last bit of code obviously doesn't work. I can't find anything on Python being able to do C++-like macros. What is the best way to condense this code?
Child.path?)'parent'and'child'as dictionary keys? Some more context would be useful.