Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 08186ee

Browse filesBrowse files
committed
make ipython pretty print more concise
1 parent e9952b1 commit 08186ee
Copy full SHA for 08186ee

File tree

Expand file treeCollapse file tree

3 files changed

+26
-24
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+26
-24
lines changed

‎spatialmath/geom3d.py

Copy file name to clipboardExpand all lines: spatialmath/geom3d.py
+3-6Lines 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

Copy file name to clipboardExpand all lines: spatialmath/super_pose.py
+7-8Lines 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

Copy file name to clipboardExpand all lines: spatialmath/twist.py
+16-10Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.