lundi 18 mars 2019

get the taken path until a line in python

Given a python function with nested if-else statements, how can we get the path we have taken to arrive to a line.

def function():
   if condition1:
      if condition2:
         sth
      else:
         get_path()
   else:
      sth

In this case get_path() should return something like function.condition1.not(condition2)

I thought about using the module inspect and seeing what is being stored in the stack frame, but I think it will require some treatment to get the path. Is there any easier way ?

Aucun commentaire:

Enregistrer un commentaire