-2

I want to print objects, so that the result is a valid python expression and can be used to reconstruct equivalent value.

Let's call this function printexp

For example,

printexp(['a', 1+2, (True, {'f': [0]}, 1/2)])

would return

"['a', 3, (True, {'f': [0]}, 0.5)]"
Monday Fatigue
  • 223
  • 1
  • 3
  • 19

1 Answers1

-1

For objects only consisting of boolean, int, float, string, list, tuple, set, and dict, you can simply use builtin print function.

Monday Fatigue
  • 223
  • 1
  • 3
  • 19