Can a line of Python code know its indentation nesting level?

前端 未结 5 622
失恋的感觉
失恋的感觉 2021-01-30 07:40

From something like this:

print(get_indentation_level())

    print(get_indentation_level())

        print(get_indentation_level())

I would li

5条回答
  •  别那么骄傲
    2021-01-30 08:24

    >>> import inspect
    >>> help(inspect.indentsize)
    Help on function indentsize in module inspect:
    
    indentsize(line)
        Return the indent size, in spaces, at the start of a line of text.
    

提交回复
热议问题