jeudi 14 novembre 2019

Get the source file line number of a function

Is there a way to accomplish this for any random function?

class Class:
    def function(self):
        pass

import inspect
print(inspect.getlineno(Class.function))

This just gives:

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\inspect.py", line 1479, in getlineno
    return frame.f_lineno
AttributeError: 'function' object has no attribute 'f_lineno'




Aucun commentaire:

Enregistrer un commentaire