For review: PEP 308 - If-then-else expression

Jp Calderone exarkun at intarweb.us
Mon Feb 10 01:08:26 EST 2003


On Mon, Feb 10, 2003 at 02:32:41AM +0000, Andrew Koenig wrote:
> >> I don't follow.  What's an "instance method" as opposed to a "class
> >> method"? [in the context of the string join method]
> 
> Erik> I presume he means something like (with S as the sequence, D as the
> Erik> string delimiter)
> 
> Erik> 	str.join(S, D)
> 
> Erik> instead of
> 
> Erik> 	D.join(S)
> 
> Eh?  str.join(D, S) works just fine, as far as I can see.

  str.join(S, D) does not, though.

  I believe the original post was suggesting something along the lines of...

class str:
    ...
    def join(cls, sequence, delimeter):
        if not sequence: return cls()
        r = cls(sequence[0])
        for s in sequence[1:]:
            r = r + delimiter + cls(s)
        return r
    join = classmethod(join)


  which I also think would be better than "delimeter.join(sequence)".  But
as others have stated, it wouldn't have worked when string methods were
first introduced, and it's pretty much too late now.  C'est la vie.

  Jp

-- 
C/C++/Java/Perl/Python/Smalltalk/PHP/ASP/XML/Linux (User+Admin)
Genetic Algorithms/Genetic Programming/Neural Networks
Networking/Multithreading/Legacy Code Maintenance/OpenGL
See my complete resume at http://intarweb.us:8080/
-- 
 up 1 day, 10:28, 2 users, load average: 0.03, 0.01, 0.00
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20030210/19448537/attachment.sig>


More information about the Python-list mailing list