Is __getitem__ what you are looking for?
class C: def __init__(self): self.my_property = "Hello" def __getitem__(self, name): return getattr(self, name) c = C() print c['my_property']
or are you looking for the opposite via __getattr__ ?
class D(dict): def __getattr__(self, name): return self[name] d = D() d['x'] = "Hello" print dx
( Edit . As Paul McGuire notes in the comments, this code only shows the bare bones of a complete solution.)
source share