Monday, February 28, 2011

PHP-like string concatenation (almost)

class PHPstr(str):
   def __getattr__(self, attr):
      return PHPstr(self+attr)

>>> a = PHPstr("test")
>>> a.test
'testtest'

Almost, but not quite the concatenation operator of PHP strings.