1
import tensorflow as tf

...

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

print(output)

Why does the last line work? Isn't output out of scope since it was declared inside the generator?

sdcbr
  • 7,021
  • 3
  • 27
  • 44

1 Answers1

2

In python with does not have scoping like methods, this post explains it more clearly Variable defined with with-statement available outside of with-block?

To save you some time

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.
Kenan
  • 13,156
  • 8
  • 43
  • 50