kj wrote:
... And actually, if speed is the criterion, then one should also avoid 
endswith:

from timeit import Timer
min(Timer("if s[-1] != '/': s += '/'", "s = 'abcd/efgh'").repeat())
0.18654584884643555
min(Timer("if not s.endswith('/'): s += '/'", "s = 'abcd/efgh'").repeat())
0.43395113945007324

_but_, try this with s = '', and you are in trouble.
So, try:

    if s[-1:] != '/':
        s += '/'

To be a trifle more reliable. But, for more normal semantics,
you might prefer either:
    if s[-1:] != '/':
        s = (s or '.') + '/'
or:
    if s and s[-1] != '/':
        s += '/'

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to