Dump function variables to workspace in python/ipython

前端 未结 5 1024
闹比i
闹比i 2021-01-14 10:06

When developing and debugging with python/ipython repl, at some point I\'d like to dump all the local variables in a function to the workspace to see what\'s going on. Suppo

5条回答
  •  死守一世寂寞
    2021-01-14 10:41

    To achieve what is directly asked for in the question, the function could return locals(), then you can update locals() in the interactive environment:

    def func():
        # define a,b,c
        return locals() # or, more restrictively, return {'a':a, 'b':b, 'c':c}
    
    >>> locals().update(func())
    

提交回复
热议问题