When you create a self-referencing nest such as discussed in the question below, you end up with [...]
representing infinite loops upon calling print
. Aside from converting the nest into a string
and replacing [...]
with a string, is there another way to detect [...]
so that I can replace it with another object (i.e. while recursing through the nested parent object)?
Asked
Active
Viewed 28 times
2
-
Use a custom method to "render" the string, dealing with reference as appropriate. I suspect that output comes from the repr. The cyclic references can be detected using an object-identity dictionary. – user2864740 Jul 17 '20 at 01:49
-
Please clarify what you want to do - do you want to detect the loop and create your own custom string, or do you just want to use the existing printout (that gets output from print) to know that the recursive loop is present? Any example of the inputs and outputs you desire or expect will make it more clear. Also, if you have tried to code it, show us what you have so far - if not, maybe at least try something simple first and post it here, with any error printouts. – LightCC Jul 17 '20 at 01:59