MCPcopy Index your code
hub / github.com/plotly/plotly.py / _list_repr_elided

Function _list_repr_elided

plotly/utils.py:9–47  ·  view source on GitHub ↗

Return a string representation for of a list where list is elided if it has more than n elements Parameters ---------- v : list Input list threshold : Maximum number of elements to display Returns ------- str

(v, threshold=200, edgeitems=3, indent=0, width=80)

Source from the content-addressed store, hash-verified

7
8# Pretty printing
9def _list_repr_elided(v, threshold=200, edgeitems=3, indent=0, width=80):
10 """
11 Return a string representation for of a list where list is elided if
12 it has more than n elements
13
14 Parameters
15 ----------
16 v : list
17 Input list
18 threshold :
19 Maximum number of elements to display
20
21 Returns
22 -------
23 str
24 """
25 if isinstance(v, list):
26 open_char, close_char = "[", "]"
27 elif isinstance(v, tuple):
28 open_char, close_char = "(", ")"
29 else:
30 raise ValueError("Invalid value of type: %s" % type(v))
31
32 if len(v) <= threshold:
33 disp_v = v
34 else:
35 disp_v = list(v[:edgeitems]) + ["..."] + list(v[-edgeitems:])
36
37 v_str = open_char + ", ".join([str(e) for e in disp_v]) + close_char
38
39 v_wrapped = "\n".join(
40 textwrap.wrap(
41 v_str,
42 width=width,
43 initial_indent=" " * (indent + 1),
44 subsequent_indent=" " * (indent + 1),
45 )
46 ).strip()
47 return v_wrapped
48
49
50class ElidedWrapper(object):

Callers 3

__repr__Method · 0.90
__repr__Method · 0.90
__repr__Method · 0.85

Calls 1

wrapMethod · 0.45

Tested by

no test coverage detected