"kj" <no.em...@please.post> 写入消息 news:h0e3p9$85...@reader1.panix.com...
In <h0e0oi$1es...@adenine.netfront.net> "tsangpo" <tsangpo.newsgr...@gmail.com> writes:

I want to ensure that the url ends with a '/', now I have to do thisa like
below.
url = url + '' if url[-1] == '/' else '/'

Is there a better way?

It's a pity that in python regexes are an "extra", as it were.
Otherwise I'd propose:

url = re.sub("/?$", "/", url)

kynn (lowest-of-the-low python noob)

look nice, but:

re.sub('/?$/', '/', 'aaabbb')
'aaabbb'

has no effect. what a pity.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to