8000 make ipython pretty print more concise · krenshaw2018/spatialmath-python@08186ee · GitHub
[go: up one dir, main page]

Skip to content

Commit 08186ee

Browse files
committed
make ipython pretty print more concise
1 parent e9952b1 commit 08186ee

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

spatialmath/geom3d.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,15 +1053,12 @@ def _repr_pretty_(self, p, cycle):
10531053
10541054
"""
10551055
if len(self) == 1:
1056-
p.begin_group(8, 'Plücker ')
10571056
p.text(str(self))
1058-
p.end_group(8, '')
10591057
else:
1060-
p.begin_group(8, 'Plücker(')
10611058
for i, x in enumerate(self):
1062-
p.break_()
1063-
p.text(str(x))
1064-
p.end_group(8, ')')
1059+
if i > 0:
1060+
p.break_()
1061+
p.text(f"{i:3d}: {str(x)}")
10651062

10661063
# function z = side(self1, pl2)
10671064
# Plucker.side Plucker side operator

spatialmath/super_pose.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -664,14 +664,13 @@ def _repr_pretty_(self, p, cycle):
664664
665665
"""
666666
# see https://ipython.org/ipython-doc/stable/api/generated/IPython.lib.pretty.html
667-
s = str(self).split('\n')
668-
p.begin_group(4, self.__class__.__name__ + ':' + s[0])
669-
p.break_()
670-
for i, s in enumerate(s[1:]):
671-
p.text(s)
672-
if i < len(s) - 2:
673-
p.break_()
674-
p.end_group(4, '')
667+
668+
if len(self) == 1:
669+
p.text(str(self))
670+
else:
671+
for i, x in enumerate(self):
672+
p.text(f"{i}:\n{str(x)}")
673+
675674

676675
def __str__(self):
677676
"""

spatialmath/twist.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,11 +1062,13 @@ def _repr_pretty_(self, p, cycle):
10621062
itself.
10631063
10641064
"""
1065-
p.begin_group(8, 'Twist3(')
1066-
for i, x in enumerate(self):
1067-
p.break_()
1068-
p.text(str(x))
1069-
p.end_group(8, ')')
1065+
if len(self) == 1:
1066+
p.text(str(self))
1067+
else:
1068+
for i, x in enumerate(self):
1069+
if i > 0:
1070+
p.break_()
1071+
p.text(f"{i:3d}: {str(x)}")
10701072

10711073
# ======================================================================== #
10721074

@@ -1552,14 +1554,18 @@ def _repr_pretty_(self, p, cycle):
15521554
itself.
15531555
15541556
"""
1555-
p.begin_group(8, 'Twist2(')
1556-
for i, x in enumerate(self):
1557-
p.break_()
1558-
p.text(str(x))
1559-
p.end_group(8, ')')
1557+
if len(self) == 1:
1558+
p.text(str(self))
1559+
else:
1560+
for i, x in enumerate(self):
1561+
if i > 0:
1562+
p.break_()
1563+
p.text(f"{i:3d}: {str(x)}")
15601564

15611565
if __name__ == '__main__': # pragma: no cover
15621566

1567+
1568+
15631569
import pathlib
15641570

15651571
exec(open(pathlib.Path(__file__).parent.parent.absolute() / "tests" / "test_twist.py").read()) # pylint: disable=exec-used

0 commit comments

Comments
 (0)
0