3 ms·
I'm still on the fence as to whether this is acceptably ugly or unacceptably ugly, but it does make use of a python feature: >>> >>> class PrefixStr: ..
by notaddicted 15y ago
I'm still on the fence as to whether this is acceptably ugly or unacceptably ugly, but it does make use of a python feature:
>>>
>>> class PrefixStr:
... def __init__(self, prefix):
... self.prefix = prefix
... def __getattr__(self, s):
... return self.prefix+s
...
>>>
>>> q = PrefixStr('xyz_')
>>>
>>> { q.height:11, q.width:7, q.depth:3 }
{'xyz_width': 7, 'xyz_depth': 3, 'xyz_height': 11}
>>>
- Estragon 15y agoThe main question is whether it increases the clarity and flexibility of the code. I can't think of any contexts where it would, but I wouldn't rule it out.
- deleted 15y ago[deleted]