2009/6/8 Aaron Brady <[email protected]>
> On Jun 7, 6:13 pm, Paul Rubin <http://[email protected]> wrote:
> > Aaron Brady <[email protected]> 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