Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
from decorator import decorator
from line_profiler import LineProfiler
def profile_each_line(func, *args, **kwargs):
profiler = LineProfiler()
profiled_func = profiler(func)
profiled_func(*args, **kwargs)
Copy link

un1t commented Nov 19, 2014

Thank for snippet. Here is little improvement

return profiled_func(*args, **kwargs)

Copy link

sibelius commented Oct 21, 2015

it's not working

Copy link

saurabh-kataria commented Jun 25, 2020

I am getting this error: AttributeError: 'NoneType' object has no attribute '__code__'

def a():
def b():

Copy link

jthistle commented Aug 16, 2020

@saurabh-kataria: you need to write:

def a():

def b():

a() in your snippet returns None (which is what all Python functions return by default), which is why you're getting the error.

Copy link

Jaya472 commented Jun 22, 2022

I am not able to see the Line Contents. Only the #hits, #time, etc are being shown. The output says

"Could not find file C:\Users\HP\AppData\Local\Temp\ipykernel_24440\
Are you sure you are running this program from the same directory that you ran the profiler from?"

It used to work few months ago but suddenly now the above is happening. And I write my scripts in Onedrive with Anaconda Jupyter Lab. Please suggest what might be wrong. There is NO answer anywhere for this problem and I tried every possible way I could think of to solve it from 8 hours! Just to get the Line Contents so that I can begin my actual task of optimizing my code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment