Suppose I have a python object x
and a string s
, how do I set the attribute s
on x
? So:
>>> x = SomeObject()
>>> attr="myAttr"
>>> # magic goes here
>>> x.myAttr
'magic'
What’s the magic? The goal of this, incidentally, is to cache calls to x.__getattr__()
.