Reputation: 23
I tried to run the following code, but got the syntax error
import tensorflow as tf
p = tf.constant("Hello")
h = tf.constant("world!")
ph = p + h
with tf.Session() as sess:
sess.run(ph)
print(sess.run(ph))
The error is like the one in image below: Syntax Error
Upvotes: 1
Views: 1111
Reputation: 166
You should include the print statement inside the with block
import tensorflow as tf
p = tf.constant("Hello")
h = tf.constant("world!")
ph = p + h
with tf.Session() as sess:
print(sess.run(ph))
As for the error, you were probably trying to run the code interactively in ipython and might have hit shift+Enter while running the with statement. Ipython complained because it did not find anything inside the block
Upvotes: 1