The print of string constant is always attached with 'b' inTensorFlow
Question:
Durng the test of TensorFlow r0.12(CPU) installed on Windows 10, I found that the printed string contant is always with an ‘b’ in the end. The print of python is normal. I cannot figure out the reason so came here for help. The code is as follows:
>>>import tensorflow as tf
>>>hello = tf.constant('Hello, TensorFlow!')
>>>sess = tf.Session()
>>>print(sess.run(hello))
b'Hello, TensorFlow!'
Answers:
Use sess.run(hello).decode()
because it is a bytestring. decode
method will return the string.
Your print statement must look like
print(sess.run(hello).decode())
Durng the test of TensorFlow r0.12(CPU) installed on Windows 10, I found that the printed string contant is always with an ‘b’ in the end. The print of python is normal. I cannot figure out the reason so came here for help. The code is as follows:
>>>import tensorflow as tf
>>>hello = tf.constant('Hello, TensorFlow!')
>>>sess = tf.Session()
>>>print(sess.run(hello))
b'Hello, TensorFlow!'
Use sess.run(hello).decode()
because it is a bytestring. decode
method will return the string.
Your print statement must look like
print(sess.run(hello).decode())