I would like to be able to add attributes to characters within a str or unicode string, chop the string and move pieces around, and have the attributes still be present at the end.
Would this be possible (and best) with a subclass of str, unicode or possibly basestring?
Example:
s = u"hello world"
s[6].foo = u'bar'
s2 = s.split(' ')
assert(s2 == u'world')
assert(s2[0].foo == u'bar')
Thanks for thoughts!
You can try using that as a starter:
Of course, you’ll have to create a specific
splitmethod, where each item of the output list will be aMineobject:The generic idea is to overload every single method of the parent class (at least, the ones you’re really interested in) so that it returns an instance of your class and inherits the
__dict__of the caller… That can be a lot of work.