human
I wrote the below code

    def _detect_ip_addr():
        from array import array
        from struct import pack, unpack
        try:
            import fcntl
        except ImportError:
            fcntl = None
        ip_addr = None
        if (not fcntl):
            host = socket.gethostname()
            ip_addr = socket.gethostbyname(host)
        else:
            nbytes = (128 * 32)
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            names = array('B', ('\x00' * nbytes))
            outbytes = unpack('iL', fcntl.ioctl(s.fileno(), 35090, pack('iL', nbytes, names.buffer_info()[0])))[0]
            namestr = names.tostring()
            for i in range(0, outbytes, 40):
                name = namestr[i:(i + 16)].split('\x00', 1)[0]
                if (name != 'lo'):
                    ip_addr = socket.inet_ntoa(namestr[(i + 20):(i + 24)])
                    break
            if (ip_addr is None):
                ifaces = filter(None, [namestr[i:(i + 32)].split('\x00', 1)[0] for i in range(0, outbytes, 32)])
                for ifname in [iface for iface in ifaces if (iface != 'lo')]:
                    ip_addr = socket.inet_ntoa(fcntl.ioctl(s.fileno(), 35093, pack('256s', ifname[:15]))[20:24])
                    break
        return (ip_addr or 'localhost')
    try:
        ip_addr = _detect_ip_addr()
    except Exception:
        ip_addr = 'localhost'
    return ip_addr

What's a good function header?
 ... Here's a good function header?
assistant
#Here's a good function header.

def detect_ip_addr():