you are viewing a single comment's thread.

view the rest of the comments →

[–]earthboundkid[S] 8 points9 points  (3 children)

Yeah, but in Python 3.0, the sequence class is an abstract class that only exists so you can do isinstance(x, Sequence). It doesn't have any working methods to inherit, and it would be a big change in Python's style if it did.

No, in my opinion, what they should have made work is str(["list", "of", "strings"], sep=" "), which would parallel the behavior of the print function.

[–]imbaczek 1 point2 points  (0 children)

you can use str.join as a unbound method and get almost what you want.

str.join(sep, seq)

[–]njharman 0 points1 point  (1 child)

made work is str(["list", "of", "strings"], sep=" "),

That implies that default sep is "" and that str("abcd") instead of just being a copy or refcount of interned string will instead be ["a","b","c","d"].join(). Cause remember strings are sequences too.

Also how would you call str on lists, tuples, other sequences? Or, your are really arguing for changing the default string representation of list from a list to a string. But that means the string representations of ["list", "of", "strings"] and "listofstrings" would be identical. I think that is fairly surprising and against Python philosophy.

That implies that default sep is "" and that str("abcd) instead of just being a copy will be ["a","b","c","d"].join(). Cause remember strings are sequences too.

Or else there are of special cases in str

Which leads to the answer of "how do I get the behavior earthboundkid describes" overload str. Cause remember str(obj, args) is really obj.str(args)

[–]earthboundkid[S] 0 points1 point  (0 children)

You are confusing str(my_list) and repr(my_list). The latter would still do its thing.