Python引入了with语句来自动帮我们调用close()方法:
eg:
f = open('/path/to/file', 'r')
print(f.read())
f.close()
等价于:
with open('/path/to/file', 'r') as f:
print(f.read())
------------------------------------------------------
同理:
with tf.Session() as sess:
print sess.run(a)
等价于:
sess = tf.Session()
print sess.run(a)
sess.close()