Message21859
Joining a list of string subtype instances usually
results in a single string instance:
>>> class mystr(str): pass
>>> type("".join([mystr("a"), mystr("b")]))
<type 'str'>
But if the list only contains one object that is a
string subtype instance, that instance is returned
unchanged:
>>> type("".join([mystr("a")]))
<class '__main__.mystr'>
This can have odd effects, for instance when the result
of "".join(lst) is used as the returnvalue of a __str__
hook. "".join should perhaps return the type of the
joining string, but definately vary its type based on
the *number* of items its joining.
|
|
Date |
User |
Action |
Args |
2007-08-23 14:24:40 | admin | link | issue1001011 messages |
2007-08-23 14:24:40 | admin | create | |
|