File: _misc.py

package info (click to toggle)
python-skbio 0.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 9,312 kB
  • sloc: python: 60,482; ansic: 672; makefile: 224
file content (27 lines) | stat: -rw-r--r-- 888 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# ----------------------------------------------------------------------------
# Copyright (c) 2013--, scikit-bio development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE.txt, distributed with this software.
# ----------------------------------------------------------------------------


def _pprint_strs(
    strs,
    max_chars=80,
    delimiter=", ",
    suffix="...",
):
    """Pretty-print an iterable of strings, truncating if necessary."""
    # Adapted from http://stackoverflow.com/a/250373
    joined_str = delimiter.join(repr(s) for s in strs)

    if len(joined_str) > max_chars:
        truncated = joined_str[: max_chars + 1].split(delimiter)[0:-1]
        joined_str = delimiter.join(truncated)
        if joined_str:
            joined_str += delimiter
        joined_str += suffix

    return joined_str