split host
# encoding:utf-8
_portprog = None
def split_host_port(host):
"""
split the host
:param host: host like : xxxx.80
:return: host,port
"""
global _portprog
if _portprog is None:
import re
_portprog = re.compile(r"^(.*)?:([0-9]*)$")
match = _portprog.match(host)
if match:
host, port = match.groups()
if port:
return host, port
return host, None
if __name__ == '__main__':
host="172.21.2.3:8009"
host,port = split_host_port(host)
print host,":",port