Here's an idea. It isn't perfect, because it doesn't work for all strings, but it might be helpful.
To set attributes of a string or any other object:
def attr(e,n,v): #will work for any object you feed it, but only that object
class tmp(type(e)):
def attr(self,n,v):
setattr(self,n,v)
return self
return tmp(e).attr(n,v)
Here's an example:
>>> def helloWorld():
... print("hello world!") #python 3
...
>>> a=attr("foo",'heloWorld',helloWorld)
>>> a
'foo'
>>> a.helloWorld()
hello world!
>>> "foo".helloWorld()
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
"foo".helloWorld()
AttributeError: 'str' object has no attribute 'helloWorld'