VGroup and VDict must override __repr__ to display the mobjects contained
See original GitHub issueConsider this example:
class Test(Scene):
def construct(self):
sq = Square()
cir = Circle()
grp = VGroup(sq, cir)
print(grp) # --> Just prints: VGroup
self.play(ShowCreation(grp))
dct = VDict({'s' : sq, 'c' : cir}).next_to(grp, DOWN)
print(dct) # --> Just prints: VDict
self.play(ShowCreation(dct))
When there are a lot of mobjects in the VGroup
or VDict
, it sometimes helps to know what are those mobjects while debugging.
Something like
[Square, Circle]
or even better the full hash name (IDK what it’s called) – manim.mobject....at 0x00...
.
Let me know how can this be best incorporated.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Source code for manim.mobject.types.vectorized_mobject
Image import Image from manim.mobject.opengl.opengl_compatibility import ... and the display will gradient to this secondary color in the direction of ...
Read more >manim/vectorized_mobject.py at main - GitHub
A community-maintained Python framework for creating mathematical animations. - manim/vectorized_mobject.py at main · ManimCommunity/manim.
Read more >How to "perfectly" override a dict? - python - Stack Overflow
You can write an object that behaves like a dict quite easily with ABCs (Abstract Base Classes) from the collections.abc module.
Read more >vocab.txt - Hugging Face
... ndarray ##pth ##uid missing report ##ugh cent hasattr org display ignore ... ##ake x1 ##cessary 24 redis ##let ##elta included overwrite ##head...
Read more >Manim is an animation engine for explanatory math videos.
Rewrite of the SVG "path" interpretation code. Added multiple SVG unit tests in small hand-created SVG files; Added multiple SVG system tests ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I don’t know the proper name either lol, but the hex thing at the end is the id, I think. And I think the id in the repr can be sometimes useful, when one wants to check if two objects are different.
I would prefer implementing
__repr__
over__str__
(see https://stackoverflow.com/questions/1436703/difference-between-str-and-repr), and would love to see more manim classes having proper__repr__
methods. (Note in particular: if__repr__
is defined and__str__
is not,str(object)
will still work.)For the container, I fully agree that its repr should print a list of its children. But for something concrete like
Square
I would find it useful to letSquare(side_length=5)
print something like'Square with side length 5'
, or even'Square with side length 5 and center (0., 0., 0.)'
; the more explicit and defining the better. (For your PR it is fine to just take care ofVGroup
andVDict
, improving their representation strings is definitely more important. 👍)