py: Add protection against printing too nested or recursive data structures.

With a test which cannot be automatically validated so far.