iPython %lprun on function within class

2019-05-26 03:13发布

问题:

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?

回答1:

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.