Delete Chars in Python
问题 does anybody know how to delete all characters behind a specific character?? like this: http://google.com/translate_t into http://google.com 回答1: if you're asking about an abstract string and not url you could go with: >>> astring ="http://google.com/translate_t" >>> astring.rpartition('/')[0] http://google.com 回答2: For urls, using urlparse: >>> import urlparse >>> parts = urlparse.urlsplit('http://google.com/path/to/resource?query=spam#anchor') >>> parts ('http', 'google.com', '/path/to