[Python-checkins] CVS: python/dist/src/Lib string.py,1.46,1.47
Fredrik Lundh
effbot at telia.com
Tue Feb 22 15:28:44 EST 2000
bjorn <bjorn at roguewave.com> wrote:
> -- python 1.6 will have *two* different string types.
>
> which presumably would be convertible, so implementing myContainer.join
for regular
> strings should be convertable to Unicode strings (no?)
I'm not sure what you mean here. do you mean that
["1", "2"].join() should return a Unicode string object,
just in case?
let's see:
"btw, now that you've installed 1.6, string.join always
return unicode strings, so your old code might no longer
work"
yeah?
> -- python 1.6 will have lots of sequence types (at
> least one more than 1.5.2!)
>
> Which is (a) a good argument for implementing join in the sequence types,
since
> there are much more than *two* sequence types <wink> and (b) suggests that
we really
> need a common base class for the sequence types to share common
functionality
> (Python is an OO language after all...)
listen very carefully:
PYTHON IS BASED ON INTERFACES, NOT ON
STRICT INHERITANCE. *ANY* OBJECT THAT
IMPLEMENTS TWO WELL-DEFINED METHODS
CAN BE USED AS A SEQUENCE OBJECT.
maybe we should change this? let's see:
"btw, now that you've installed 1.6, your old sequence
classes no longer work. you have to make sure they all
inherit from AbstractSequence. if you're using C types,
you're SOL"
really?
> -- while join can be *defined* as a series of concatenations,
> *implementing* things that way doesn't work in real life. do
> you really think that *all* sequence objects should know
> how to join all possible string types in an efficient way? or
> is that better left to the string implementation?
>
> Conversely, to you really think that both string classes should know how
to
> efficiently join all possible sequence types?
yes, because all they have to do is to use the abstract
sequence interface:
http://www.python.org/doc/current/api/abstract.html
> Consider:
>
> class MyTree:
> def join(sep=''):
> lhs = rhs = ''
> if self.lhs:
> lhs = self.join(self.lhs)
> if self.rhs:
> rhs = self.join(self.rhs)
> # presumably the + operator would do any neccessary coercion?
> return lhs + sep + self.data + sep + rhs
>
> sometimes implementing join as a series of concatenations does work
only if you don't give a damn about performance...
"btw, now that you've installed 1.6, string.join is
slow as hell. you might as well use reduce"
forget it. won't happen.
</F>
More information about the Python-list
mailing list