Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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}
  >>>


The 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: