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

Python Tensorflow会话-会话上下文的范围?,python,tensorflow,scope,Python,Tensorflow,Scope,为什么最后一行有用?由于输出是在生成器中声明的,所以它不是超出了范围吗?在python中,with没有类似作用域的方法,本文对此进行了更清楚的解释 为了节省你的时间 import tensorflow as tf ... with tf.Session() as sess: output = sess.run(result) print(output) print(output) the context manager will be available outside

为什么最后一行有用?由于输出是在生成器中声明的,所以它不是超出了范围吗?

在python中,
with
没有类似作用域的方法,本文对此进行了更清楚的解释

为了节省你的时间

import tensorflow as tf

...

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

print(output)
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.