2

I have had this 'not so important' question in many conditions, and the specific question I meet most recently is:

import tensorflow as tf
help(tf.feature_column.numeric_column)

[output]:
Help on function numeric_column in module 
tensorflow.python.feature_column.feature_column: 
...

So, here is my question. The complete reference of

'tf.feature_column.numeric_column'

is

'tensorflow.python.feature_column.feature_column'

according to its docstrings. Why the 'python' package name could be omitted?

I thought that python may be able to find package/module in next hierarchy automatically?

Leo
  • 71
  • 4

1 Answers1

3

Tensorflow imports the python module into its init.py file

from tensorflow.python import *
Sayse
  • 42,633
  • 14
  • 77
  • 146
  • If I run: from a.b import c I could refer c by a.c rather than a.b.c? – Leo Nov 03 '17 at 08:01
  • @Leo - In the link provided, you can see that in the tensorflow modules init file they are importing everything from the python module with the *, making all its contents available to the tensorflow module. If you were to do the same, then you could too but I'd suggest only doing this if you have a real need to (I can't really comment on why TF did this) – Sayse Nov 03 '17 at 08:09
  • Forgive me for not learning so deep in python. As we know, if we run 'from a.b import c' or 'from a.b import *', we could refer c directly other than have to refer c by hierarchy i.e. 'a.b.c'. So my concrete question here is why we could use 'a.c' rather/other than 'c' or 'a.b.c' in tensorflow. Is this owing to tensorflow's particularity or init.py's particularity? And I think the latter is much more possible. If my thought is true, could you explain such init.py's particularity for me? Thanks a lot! – Leo Nov 03 '17 at 08:28
  • @Leo - I'm not sure which bit needs explaining, perhaps ["What exactly does “import *” import?"](https://stackoverflow.com/q/2360724/1324033) could help further, there isn't anything tensorflow specific here – Sayse Nov 03 '17 at 08:35
  • 1
    Anyway, thanks a lot! And I just wanna to say some bit may be obvious and shallow to the sophisticated may just some beginner's confusion. : ) – Leo Nov 03 '17 at 08:53
  • 1
    Oh, I got it. Your first answer has answered my question. Sorry for not realizing until now. After ' from tensorflow.python import * ', tensorflow could see everything in python and could omit '.python' when referring. Just as i said some bit may be obvious and shallow to the sophisticated may be just some beginner's confusion. Thanks!! – Leo Nov 03 '17 at 09:05
  • @Leo - No worries, thats right, it just exposes pythons contents into tensorflows scope – Sayse Nov 03 '17 at 09:07