2009/6/8 Aaron Brady <castiro...@gmail.com>

> On Jun 7, 6:13 pm, Paul Rubin <http://phr...@nospam.invalid> wrote:
> > Aaron Brady <castiro...@gmail.com> writes:
> > > url+= { '/': '' }.get( url[ -1 ], '/' )
> >
> > > Shorter is always better.
> >
> > url = url.rstrip('/') + '/'
>
> I was joking.  Sheesh.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

my two cents: a solution based on regex: the pattern replaces all slashes at
the end of the string with a single one. The * usage matches also the empty
group of slashes (example s2)

>>> print s1
aaaaa/
>>> print s2
bbbb
>>> re.sub('[/]*$','/', s1)
'aaaaa/'
>>> re.sub('[/]*$','/', s2)
'bbbb/'

-Roland
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to