Question

When I ask an ipython notebook to display (via evaluate) a large np.array ipython uses ellipses to summarize the data. However if I ask ipython to display a large list, no such safe guard is in place and my poor ipython notebook struggles. Are there any magics or other tools I can use? I run an ipython notebook in emacs.

Was it helpful?

Solution

What you want is to add display support to existing object (example with polynomial and TeX) (those you can't tamper the source with) what you are trying to define is a "pretty Formatter" (aka _repr_pretty_) for those. You will have a difficulty compared to numpy arrays which is that list are heterogeneous, and so the first element can be a really supper long element.

You can also look at the plain doc for existing formatters, to get an idea.

OTHER TIPS

could you not just test the length of the list yourself? Or wrap the lists as generators?

>>> def guard(XS,N):
...     if len(XS) > N:
...         return "list too long" # or whatever you want
...     else:
...         return XS
... 
>>> guard([1,2,3,4],2)
'list too long'
>>> guard([1,2,3,4],6)
[1, 2, 3, 4]
>>> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top