Print list of namedtuples into a table using prtfmt.
335256
def prt_nts(data_nts, prtfmt=None, prt=sys.stdout, nt_fields=None, **kws):
    """"""
    prt_txt(prt, data_nts, prtfmt, nt_fields, **kws)
1197230
def get_prtfmt_list(self, flds, add_nl=True):
        """"""
        fmts = []
        for fld in flds:
            if fld[:2] == 'p_':
                fmts.append('{{{FLD}:8.2e}}'.format(FLD=fld))
            elif fld in self.default_fld2fmt:
                fmts.append(self.default_fld2fmt[fld])
            else:
                raise Exception("UNKNOWN FORMAT: {FLD}".format(FLD=fld))
        if add_nl:
            fmts.append("\n")
        return fmts
1120683
def pretty_print_list(lst, name = 'features', repr_format=True):
    
    if not lst or len(lst) < 8:
        if repr_format:
            return lst.__repr__()
        else:
            return ', '.join(map(str, lst))
    else:
        topk = ', '.join(map(str, lst[:3]))
        if repr_format:
            lst_separator = "["
            lst_end_separator = "]"
        else:
            lst_separator = ""
            lst_end_separator = ""

        return "{start}{topk}, ... {last}{end} (total {size} {name})".format(\
                topk = topk, last = lst[-1], name = name, size = len(lst),
                start = lst_separator, end = lst_end_separator)
586005
def _list_stmt(self, stmt: Statement, sctx: SchemaContext) -> None:
        """"""
        self._handle_child(ListNode(), stmt, sctx)
1041041
def list(cls,
             l,
             order=None,
             header=None,
             output="table",
             sort_keys=True,
             show_none=""
             ):
        
        d = {}
        count = 0
        for entry in l:
            name = str(count)
            d[name] = entry
            count += 1
        return cls.dict(d,
                        order=order,
                        header=header,
                        sort_keys=sort_keys,
                        output=output,
                        show_none=show_none)
1339857
def _output(cls,
            tensors: Sequence[tf.Tensor],
            dtypes: Sequence[tf.DType]) -> Sequence[tf.Tensor]:
        ''''''
        outputs = []
        for tensor, dtype in zip(tensors, dtypes):
            tensor = tensor[0]
            if tensor.dtype != dtype:
                tensor = tf.cast(tensor, dtype)
            outputs.append(tensor)
        return tuple(outputs)
387518
def _print_refs(self, fobj, refs, total, level=1, minsize=0, minpct=0.1):
        
        lrefs = list(refs)
        lrefs.sort(key=lambda x: x.size)
        lrefs.reverse()
        if level == 1:
            fobj.write('<table>\n')
        for ref in lrefs:
            if ref.size > minsize and (ref.size*100.0/total) > minpct:
                data = dict(level=level,
                            name=trunc(str(ref.name), 128),
                            size=pp(ref.size),
                            pct=ref.size*100.0/total)
                fobj.write(self.refrow % data)
                self._print_refs(fobj, ref.refs, total, level=level+1)
        if level == 1:
            fobj.write("</table>\n")
912374
def prt_txt(prt, data_nts, prtfmt=None, nt_fields=None, **kws):
    """"""
    lines = get_lines(data_nts, prtfmt, nt_fields, **kws)
    if lines:
        for line in lines:
            prt.write(line)
    else:
        sys.stdout.write("      0 items. NOT WRITING\n")
545457
def prt_txt(prt, goea_results, prtfmt=None, **kws):
        """"""
        objprt = PrtFmt()
        if prtfmt is None:
            flds = ['GO', 'NS', 'p_uncorrected',
                    'ratio_in_study', 'ratio_in_pop', 'depth', 'name', 'study_items']
            prtfmt = objprt.get_prtfmt_str(flds)
        prtfmt = objprt.adjust_prtfmt(prtfmt)
        prt_flds = RPT.get_fmtflds(prtfmt)
        data_nts = MgrNtGOEAs(goea_results).get_goea_nts_prt(prt_flds, **kws)
        RPT.prt_txt(prt, data_nts, prtfmt, prt_flds, **kws)
        return data_nts
1036664
def _get_prtfmt(self, objgowr, verbose):
        """"""
        prtfmt = objgowr.get_prtfmt('fmt')
        prtfmt = prtfmt.replace('# ', '')
        # print('PPPPPPPPPPP', prtfmt)
        if not verbose:
            prtfmt = prtfmt.replace('{hdr1usr01:2}', '')
            prtfmt = prtfmt.replace('{childcnt:3} L{level:02} ', '')
            prtfmt = prtfmt.replace('{num_usrgos:>4} uGOs ', '')
            prtfmt = prtfmt.replace('{D1:5} {REL} {rel}', '')
            prtfmt = prtfmt.replace('R{reldepth:02} ', '')
        # print('PPPPPPPPPPP', prtfmt)
        marks = ''.join(['{{{}}}'.format(nt.hdr) for nt in self.go_ntsets])
        return '{MARKS} {PRTFMT}'.format(MARKS=marks, PRTFMT=prtfmt)
105364
def prt_mdtbl(self, nts, prt_flds=None, prt=sys.stdout):
        """"""
        if prt_flds is None:
            prt_flds = self.prt_flds
        prtfmt = "|{DATA}|\n".format(DATA="|".join(self.fld2prtfmt[f] for f in prt_flds))
        prt_txt(prt, nts, prtfmt=prtfmt)
439424
def _pprint(dic):
    """"""
    for key, value in dic.items():
        print("        {0}: {1}".format(key, value))
383980
def print_table(data, title=None):
    
    if isinstance(data, dict):
        data = list(data.items())
    tpl_row = '    {:<15}' * len(data[0])
    table = '\n'.join([tpl_row.format(l, unicode_(v)) for l, v in data])
    if title:
        print('\n    \033[93m{}\033[0m'.format(title))
    print('\n{}\n'.format(table))
1263417
def to_named_tuple(keys, values):
    

    values = [dbobject.__dict__[key] for key in dbobject.keys()]

    tuple_object = namedtuple('DBObject', dbobject.keys())

    tuple_instance = tuple_object._make(values)

    return tuple_instance
413083
def print_table(rows, override_headers=None, uppercase_headers=True):
    """"""
    if len(rows) == 0:
        return
    keys = list(rows[0].keys())
    headers = override_headers or keys
    if uppercase_headers:
        rows = [dict(zip(keys,
                         map(lambda x: x.upper(), headers))), None] + rows
    else:
        rows = [dict(zip(keys, headers)), None] + rows

    lengths = [max(len(str(row[k]))
                   for row in rows if hasattr(row, '__iter__')) for k in keys]
    tmp = ['{%s:%i}' % (h, l) for h, l in zip(keys[: -1], lengths[: -1])]
    tmp.append('{%s}' % keys[-1])
    template = (' ' * 4).join(tmp)

    for row in rows:
        if type(row) == str:
            print(row)
        elif row is None:
            print()
        elif isinstance(row, dict): 
            row = {k: v if v is not None else 'None' for k, v in row.items()}
            print(template.format(**row))
        else:
            print("Unhandled row type:", row)
554223
def prt_data(self, name, vals, prt=sys.stdout):
        """"""
        fld2val = self.get_fld2val(name, vals)
        prt.write(self.fmt.format(**fld2val))
        return fld2val
1122675
def pprint(self):
        """"""
        strings = []
        for key in sorted(self.keys()):
            values = self[key]
            for value in values:
                strings.append("%s=%s" % (key, value))
        return "\n".join(strings)