Hi all,
I have some code in Python where I'll have a bunch of classes, each of which will have an attribute _internal_attribute
. I would like to be able to generate a mapping of those attributes to the original class. Essentially I would like to be able to do this:
class A(object):
_internal_attribute = 'A attribute'
class B(object):
_internal_attribute = 'B attribute'
a_instance = magic_reverse_mapping['A attribute']()
b_instance = magic_reverse_mapping['B attribute']()
What I'm missing here is how to generate magic_reverse_mapping
dict. I have a gut feeling that having a metaclass generate A and B is the correct way to go about this; does that seem right?