python3 如何找到对象源代码所在位置
有时候找不到某个对象得源代码在哪。
例如:
LOG.debug("DVR: add fip namespace sleep self.driver.plug: %s", self.driver.plug)
输出是
<bound method LinuxInterfaceDriver.plug of <neutron.agent.linux.interface.OVSInterfaceDriver object at 0x7f91b8dd3f70>>
解决:
import inspect
LOG.debug("DVR: add fip namespace sleep self.driver.plug: %s", inspect.getsourcefile(self.driver.plug))
此时日志输出得是:
/usr/lib/python3/dist-packages/neutron/agent/linux/interface.py
就知道此对象代码所在位置了。
就知道此对象代码所在位置了。