Tensorflow会话-会话上下文的范围?

时间:2018-07-30 19:40:53

标签: python tensorflow scope

import tensorflow as tf

...

with tf.Session() as sess:
    output = sess.run(result)
    print(output)

print(output)

为什么最后一行有效?由于output是在生成器内部声明的,因此不超出范围吗?

1 个答案:

答案 0 :(得分:2)

在python with中没有类似作用域的方法,这篇文章对此进行了更清晰的解释 Variable defined with with-statement available outside of with-block?

为了节省您一些时间

the context manager will be available outside the with statement and that is not implementation or version dependent. with statements do not create a new execution scope.