Bastiaan
Bastiaan

Reputation: 4672

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

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!

Upvotes: 3

Views: 827

Answers (2)

user2357112
user2357112

Reputation: 281167

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.

Upvotes: 6

robotHamster
robotHamster

Reputation: 649

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

Upvotes: -3

Related Questions