Skip to content
This repository was archived by the owner on Dec 2, 2021. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions 10-seq-hacking/vector_v5.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down