MCPcopy Index your code
hub / github.com/pywebio/PyWebIO / put_table

Function put_table

pywebio/output.py:612–708  ·  view source on GitHub ↗

Output table :param list tdata: Table data, which can be a two-dimensional list or a list of dict. The table cell can be a string or ``put_xxx()`` call. The cell can use the :func:`span()` to set the cell span. :param list header: Table header. When the item of ``tdata``

(tdata: List[Union[List, Dict]], header: List[Union[str, Tuple[Any, str]]] = None, scope: str = None,
              position: int = OutputPosition.BOTTOM)

Source from the content-addressed store, hash-verified

610
611@safely_destruct_output_when_exp('tdata')
612def put_table(tdata: List[Union[List, Dict]], header: List[Union[str, Tuple[Any, str]]] = None, scope: str = None,
613 position: int = OutputPosition.BOTTOM) -> Output:
614 """
615 Output table
616
617 :param list tdata: Table data, which can be a two-dimensional list or a list of dict.
618 The table cell can be a string or ``put_xxx()`` call. The cell can use the :func:`span()` to set the cell span.
619 :param list header: Table header.
620 When the item of ``tdata`` is of type ``list``, if the ``header`` parameter is omitted,
621 the first item of ``tdata`` will be used as the header.
622 The header item can also use the :func:`span()` function to set the cell span.
623
624 When ``tdata`` is list of dict, ``header`` can be used to specify the order of table headers.
625 In this case, the ``header`` can be a list of dict key or a list of ``(<label>, <dict key>)``.
626
627 :param int scope, position: Those arguments have the same meaning as for `put_text()`
628
629 Example:
630
631 .. exportable-codeblock::
632 :name: put_table
633 :summary: Output table with `put_table()`
634
635 # 'Name' cell across 2 rows, 'Address' cell across 2 columns
636 put_table([
637 [span('Name',row=2), span('Address', col=2)],
638 ['City', 'Country'],
639 ['Wang', 'Beijing', 'China'],
640 ['Liu', 'New York', 'America'],
641 ])
642 ## ----
643
644 # Use `put_xxx()` in `put_table()`
645 put_table([
646 ['Type', 'Content'],
647 ['html', put_html('X<sup>2</sup>')],
648 ['text', '<hr/>'],
649 ['buttons', put_buttons(['A', 'B'], onclick=...)], # ..doc-only
650 ['buttons', put_buttons(['A', 'B'], onclick=put_text)], # ..demo-only
651 ['markdown', put_markdown('`Awesome PyWebIO!`')],
652 ['file', put_file('hello.text', b'hello world')],
653 ['table', put_table([['A', 'B'], ['C', 'D']])]
654 ])
655 ## ----
656
657 # Set table header
658 put_table([
659 ['Wang', 'M', 'China'],
660 ['Liu', 'W', 'America'],
661 ], header=['Name', 'Gender', 'Address'])
662 ## ----
663
664 # When ``tdata`` is list of dict
665 put_table([
666 {"Course":"OS", "Score": "80"},
667 {"Course":"DB", "Score": "93"},
668 ], header=["Course", "Score"]) # or header=[(put_markdown("*Course*"), "Course"), (put_markdown("*Score*") ,"Score")]
669

Callers 9

targetFunction · 0.85
basic_outputFunction · 0.85
show_popupFunction · 0.85
mainFunction · 0.85
output_widgetsFunction · 0.85
show_popupFunction · 0.85
pageFunction · 0.85
mainFunction · 0.85
show_goboardFunction · 0.85

Calls 3

_get_output_specFunction · 0.85
OutputClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…