3 ms·
See also rsplit(':', 1). But instead of either of those, you should really be using library functions that already understand the format in question instead of
by anderskaseorg 8y ago
See also rsplit(':', 1). But instead of either of those, you should really be using library functions that already understand the format in question instead of making up your own rules.
>>> u = urllib.parse.ParseResult('', '[2001:0db8:f00f::0553:1211:0088]:10443', '', '', '', '')
>>> u.hostname
'2001:0db8:f00f::0553:1211:0088'
>>> ipaddress.ip_address(u.hostname)
IPv6Address('2001:db8:f00f::553:1211:88')
>>> u.port
10443