How to find a class or function in a Python module?

徘徊边缘 提交于 2019-12-31 03:53:09

问题


I'm trying to find the function or class definition of gen_dataset_ops in tensorflow, which has its sourcecode here. I find many places where it is imported like so:

from tensorflow.python.ops import gen_dataset_ops

But I can't find where it is defined, I'd expect to find something like:

def gen_dataset_ops(...):
  #Do something clever
  return

I don't quite understand the anatomy of python modules in general, so I'm probably missing some basics here,.. any hint is welcome!


回答1:


tensorflow.python.ops.gen_dataset_ops is generated code. (That's why they put gen in front of the name.) You can't find it in the source repository because it's not in the source repository; it only comes into existence during the Tensorflow build process.

If you have Tensorflow installed, you should be able to find gen_dataset_ops.py under tensorflow/python/ops/gen_dataset_ops.py in your Tensorflow installation.




回答2:


I would navigate to your python directory (this example is for a virtualenv on ubuntu):

~/pyEnvs/env1/lib/python2.7/site-packages/tensorflow/python/ops.py and open that file. In that file, use Ctrl+F and find the function you are looking for.

My answer assumes you know where your python environment is installed and that you installed tensorflow using pip



来源:https://stackoverflow.com/questions/46613055/how-to-find-a-class-or-function-in-a-python-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!