Get function import path

后端 未结 2 720
名媛妹妹
名媛妹妹 2021-02-12 18:16
from pack.mod import f

How to get from object f information about import - \'pack.mod\'

I can get it using f.__module__

2条回答
  •  再見小時候
    2021-02-12 18:58

    You want the __name__ attribute from __module__:

    In [16]: import inspect
    In [17]: inspect.getmodule(MyObject).__name__
    Out[17]: 'lib.objects.MyObject'
    

提交回复
热议问题