Can a line of Python code know its indentation nesting level?
问题 From something like this: print(get_indentation_level()) print(get_indentation_level()) print(get_indentation_level()) I would like to get something like this: 1 2 3 Can the code read itself in this way? All I want is the output from the more nested parts of the code to be more nested. In the same way that this makes code easier to read, it would make the output easier to read. Of course I could implement this manually, using e.g. .format() , but what I had in mind was a custom print function