Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPython %lprun on function within class

Tags:

python

ipython

I'm wondering how to do %lprun on a python script in a class stucture.

Say I want to see what's taking so long in run():

example.py

def outside_call():
    mc = MLIC()
    mc.run()

class MLIC(object):

    def __init__():
        pass
    def run():
       #Profile this function

Normally if run() wasn't in a class, I would use:

%lprun -f example.run example.run()

Now I need like...

%lprun -f example.MLIC.run() example.outside_call()

How do I accomplish this?

like image 373
user1610719 Avatar asked Feb 03 '26 19:02

user1610719


1 Answers

I'm an idiot.

In this case, you can actually do:

%lprun -f example.MLIC.run() example.outside_call()

I thought I tried it but typed it wrong.

like image 117
user1610719 Avatar answered Feb 05 '26 09:02

user1610719



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!