diff --git a/10-seq-hacking/vector_v5.py b/10-seq-hacking/vector_v5.py index cf327bc..59f598e 100644 --- a/10-seq-hacking/vector_v5.py +++ b/10-seq-hacking/vector_v5.py @@ -269,15 +269,24 @@ def angles(self): # <3> return (self.angle(n) for n in range(1, len(self))) def __format__(self, fmt_spec=''): + ellipsis = '' + limit_num = len(self) + if fmt_spec.endswith('*'): + fmt_spec = fmt_spec[:-1] + elif len(self) > 30: + limit_num = 30 + ellipsis = ', ...' + if fmt_spec.endswith('h'): # hyperspherical coordinates fmt_spec = fmt_spec[:-1] coords = itertools.chain([abs(self)], self.angles()) # <4> - outer_fmt = '<{}>' # <5> + outer_fmt = '<{{}}{}>'.format(ellipsis) # <5> else: coords = self - outer_fmt = '({})' # <6> - components = (format(c, fmt_spec) for c in coords) # <7> + outer_fmt = '({{}}{})'.format(ellipsis) # <6> + components = (format(c, fmt_spec) + for c in itertools.islice(coords, limit_num)) # <7> return outer_fmt.format(', '.join(components)) # <8> @classmethod