The difference between simply calling a Python function and porting it to cProfile.run ()

I have a pretty simple Python script that contains a function call like

f(var, other_var)

i.e. a function that receives several parameters. All these parameters can be obtained within f and have values.

When I call instead

cProfile.run('f(var, other_var)')

it crashes with an error message:

NameError: "name 'var' is not defined"

Python version

Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin

What's going on here?

+3
source share
1 answer

, cProfile exec , , var ! run(), cProfile , , . runctx, exec ed:

cProfile.runctx( "...", globals(), locals() )
+9

Source: https://habr.com/ru/post/1759096/


All Articles