def ports_for_pids(pids):
        LSOF_ARGS = ["lsof", "-i", "-n", "-P"]
        # lsof is an external command, so won't always be present
        try:
            lsof = Popen(LSOF_ARGS, stdout=PIPE,
                stderr=PIPE).communicate()[0].split("\n")
        except:
            return
        addr_pos = None
        pid_pos = None
        addr_heading = "NAME"
        pid_heading = "PID"
        for row in lsof:
            if addr_heading in row and row in pid_heading:
                addr_pos = row.index(addr_heading)
                pid_pos = row.index(pid_heading)-2
            if addr_pos is not None:
                pid = row[pid_pos:].split(" ")[0]
                if pid in pids:
                    port = row[addr_pos:].split(":")[1].split(" ", 1)[0]
                    yield (pid, port)
dataset/ETHPy150Open stephenmcd/gunicorn-console/gunicorn_console.py/ports_for_pids/swapped operands of `in`