def ip_interface(address):
 try:
  return IPv4Interface(address)
 except (AddressValueError, NetmaskValueError):
  pass
 try:
  return IPv6Interface(address)
 except (AddressValueError, NetmaskValueError):
  pass
 raise ValueError(('%r does not appear to be an IPv4 or IPv6 interface' % address))

def ip_interface ( address ) : try : return IPv4Interface ( address ) except ( AddressValueError , NetmaskValueError ) : pass try : return IPv6Interface ( address ) except ( AddressValueError , NetmaskValueError ) : pass raise ValueError ( ( '%r does not appear to be an IPv4 or IPv6 interface' % address ) )
take an ip string/int and return an object of the correct type .