字符串常量的打印总是在TensorFlow中附加'b' [英] The print of string constant is always attached with 'b' inTensorFlow
本文介绍了字符串常量的打印总是在TensorFlow中附加'b'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在对安装在 Windows 10 上的 TensorFlow r0.12(CPU) 进行测试时,我发现打印的字符串内容总是以b"结尾.python的打印是正常的.我无法弄清楚原因所以来这里寻求帮助.代码如下:
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!'
推荐答案
使用 sess.run(hello).decode()
因为它是一个字节串.decode
方法将返回字符串.
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())
这篇关于字符串常量的打印总是在TensorFlow中附加'b'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文