Transform a list of strings into a single string with columns. Parameters ---------- items : sequence of strings The strings to process. row_first : (default False) Whether to compute columns for a row-first matrix instead of column-first (default). se
(items, row_first=False, separator=' ', displaywidth=80, spread=False)
| 708 | |
| 709 | |
| 710 | def columnize(items, row_first=False, separator=' ', displaywidth=80, spread=False): |
| 711 | """ Transform a list of strings into a single string with columns. |
| 712 | |
| 713 | Parameters |
| 714 | ---------- |
| 715 | items : sequence of strings |
| 716 | The strings to process. |
| 717 | |
| 718 | row_first : (default False) |
| 719 | Whether to compute columns for a row-first matrix instead of |
| 720 | column-first (default). |
| 721 | |
| 722 | separator : str, optional [default is two spaces] |
| 723 | The string that separates columns. |
| 724 | |
| 725 | displaywidth : int, optional [default is 80] |
| 726 | Width of the display in number of characters. |
| 727 | |
| 728 | Returns |
| 729 | ------- |
| 730 | The formatted string. |
| 731 | """ |
| 732 | if not items: |
| 733 | return '\n' |
| 734 | matrix, info = compute_item_matrix(items, row_first=row_first, separator_size=len(separator), displaywidth=displaywidth) |
| 735 | if spread: |
| 736 | separator = separator.ljust(int(info['optimal_separator_width'])) |
| 737 | fmatrix = [filter(None, x) for x in matrix] |
| 738 | sjoin = lambda x : separator.join([ y.ljust(w, ' ') for y, w in zip(x, info['column_widths'])]) |
| 739 | return '\n'.join(map(sjoin, fmatrix))+'\n' |
| 740 | |
| 741 | |
| 742 | def get_text_list(list_, last_sep=' and ', sep=", ", wrap_item_with=""): |
nothing calls this directly
no test coverage detected