0

I am reading through some code and was trying to look where the files where imported from. I read through this thread Retrieving python module path and so I tried

print _init_paths.__file__ 

which worked. But when I tried

print fast_rcnn.train.__file__

I get an error saying NameError: name 'fast_rcnn' is not defined. Note that the following 3 lines below have no errors i.e. the files have been successfully imported.

import _init_paths
from fast_rcnn.train import get_training_roidb, train_net
from fast_rcnn.config import cfg, cfg_from_file, cfg_from
Community
  • 1
  • 1
Kong
  • 2,202
  • 8
  • 28
  • 56
  • 6
    Well you haven't actually imported the name `fast_rcnn` - try `import fast_rcnn; print fast_rcnn.__file__`. Alternatively, if you don't want to import that module, try `sys.modules['fast_rcnn'].__file__` (for which you will also need to `import sys`). – jonrsharpe Dec 04 '16 at 14:48
  • Sorry I forgot to mention that fast_rcnn is a folder and that train is the python file I am importing. I was wondering if I could get the location of train.py which is in the folder fast_rcnn. – Kong Dec 04 '16 at 14:50
  • If you know where that file is, then what exactly is the problem? – jonrsharpe Dec 04 '16 at 14:51
  • Im just trying to learn new things. Plus it took me awhile to find out where the file was located so it would be nice if I could print a path to it directly for future use. – Kong Dec 04 '16 at 14:55
  • 1
    Well in general, you need to have the actual name of the thing you want to find - `from fast_rcnn import train; print train.file`, or `import fast_rcnn; print fast_rcnn.train.__file__`. – jonrsharpe Dec 04 '16 at 15:01
  • Ah okay so the only solution is to import the folder then print the location of the file within that folder. Thanks ! – Kong Dec 04 '16 at 15:10

0 Answers0