[Python] Retreiving/Printing current execution context
I am currently writing a swarm intelligence simulator and looking to give the user an easy way to debug their algorithms. Among other outputs, I feel it would be beneficial to give the user a printout of the execution context at the beginning of each step in the algorithm.

I envisage something along the lines of:

    def print_current_execution__context():
        #?????

    class TheClass(object):
        def __init__(self,val):
            self.val=val
        def thefunction(self,a,b):
            c=a+b
            print_current_execution_context()

    
    C=TheClass(2)
    C.thefunction(1,2)


An expected output might be something along the lines of:

    {a:1,b:2,c:3,self:<TheClass instance at 0x12345678>}

I understand that `__dict__` can be used to retrieve instance variables (such as self.var), however I am not aware of anything similar for functions.


I've investigated a number of the debugging tools such as trace and inspect, and have probably overlooked something, but I can't seem to make them return execution context (other than stack based calls).

Hopefully someone here can point me in the right direction,
Cheers,
Mike


[Python] Retreiving/Printing current execution context
===

I am currently writing a swarm intelligence simulator and looking to give the user an easy way to debug their algorithms. Among other outputs, I feel it would be beneficial to give the user a printout of the execution context at the beginning of each step in the algorithm.

I envisage something along the lines of:

    def print_current_execution__context():
        #?????

    class TheClass(object):
        def __init__(self,val):
            self.val=val
        def thefunction(self,a,b):
            c=a+b
            print_current_execution_context()

    
    C=TheClass(2)
    C.thefunction(1,2)


An expected output might be something along the lines of:

    {a:1,b:2,c:3,self:<TheClass instance at 0x12345678>}

I understand that `__dict__` can be used to retrieve instance variables (such as self.var), however I am not aware of anything similar for functions.


I've investigated a number of the debugging tools such as trace and inspect, and have probably overlooked something, but I can't seem to make them return execution context (other than stack based calls).

Hopefully someone here can point me in the right direction,
Cheers,
Mike

