【问题标题】:"import ... as .." trigger AttributeError“import ... as ..” 触发 AttributeError
【发布时间】:2018-05-12 16:42:37
【问题描述】:

当我使用“import as”时

import tensorflow.python.ops.control_flow_ops as ass

我得到“AttributeError:模块'tensorflow'没有属性'python'”

但下面的代码喜欢

import tensorflow.python.ops.control_flow_ops

工作正常

环境:python 3.6.3 + tensorflow 1.3.0

【问题讨论】:

  • from tensorflow.python.ops import control_flow_ops as ass
  • 这很好用,但是正如我在问题中描述的那样,“as”是如何导致问题的

标签: python tensorflow


【解决方案1】:

这是 TensorFlow 接口密封(例如,从 import tensorflow as tf 中删除 tf.python 符号可见性)和 Python import semantics 的不幸组合。 import tensorflow... as 语法只能访问公共 TensorFlow 符号,而 from tensorflow... import ... as 也可以访问没有 API stability guarantees 的私有符号。

【讨论】:

    猜你喜欢
    • 2019-04-23
    • 2018-11-16
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多