My objective is to identify the exact indentation of a code line in a python file. Since i would be instrumenting statements at some location, determining the required indentation of of a line is important to achieve my goal. The problem can be explained in the following example:
First Scenario
#A.py
a=0 <----------- indentation '0' spaces or '0' \t
while a<5: <----------- indentation '0' spaces or '0' \t
print a <----------- indentation '4' spaces or '1' \t
a=a+1 <----------- indentation '4' spaces or '1' \t
Second scenario
#A.py
a=0 <----------- indentation '0' spaces or '0' \t
while a<5: <----------- indentation '0' spaces or '0' \t
print a <----------- indentation '8' spaces or '2' \t
a=a+1 <----------- indentation '8' spaces or '2' \t
Since i am inspecting an application consisting of many files i come across files with the above scenarios. I would like to know how to determine the indentation of any line in a python file?