I am trying to profile a part of my program. The pattern is like the following:
def de():
def abc():
print("123")
cProfile.run('abc()')
When I am trying to run this program, I got an error: File "", line 1, in NameError: name 'abc' is not defined
Is there anyway to work around this error?
Everything happening outside of the function, meaning that they are hidden from the global scope.
use runctx(). Please read https://docs.python.org/3/library/profile.html#profile.runctx
import cProfile
def de():
def abc():
print("123")
cProfile.runctx('abc()', None, locals=locals())
de()
output:
"123"
5 function calls in 0.000 seconds
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With