join vs instances

Michael Hudson mwh at python.net
Mon Dec 10 06:56:03 EST 2001


Robin Becker <robin at jessikat.fsnet.co.uk> writes:

> what do I need in a class to get an instance to respect the string
> join?

Unfortunately, you can't.

There is no satisfactory distinction on when things like this work and
when they don't, but there's a general movement in favour of being
more flexible, i.e. ''.join(UserString('ab')) might work at some
point.  Doesn't seem to in 2.2b2+, though.

As a work around, it you control the call of string.join, replace

    sep.join(seq)

with

    sep.join(map(str, seq))

HTH,
M.

-- 
  Good? Bad? Strap him into the IETF-approved witch-dunking
  apparatus immediately!                        -- NTK now, 21/07/2000



More information about the Python-list mailing list