+-
python – TensorFlow中实际输出之前的额外’b’
参见英文答案 > What does the ‘b’ character do in front of a string literal?                                    8个
>             Tensorflow outputs an additional ‘b’ when evaluating a string tensor                                     1个
所以,我是TensorFlow的新手,并且刚刚开始学习它.我使用’pip’命令在IDE Canopy上安装了TensorFlow.

在确认是否已正确安装时,我输入了以下代码:

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

这应该给出一个输出:

Hello, TensorFlow!

相反,我在这之前得到一个额外的字母’b’,如:

b'Hello, TensorFlow!'

这是一个要排序的问题还是没问题,如果我对此没有做任何事情就可以了?
非常感谢.

最佳答案
‘b’表示它是一个字节串(而不是八位字节序列).使用decode()来获取字符串.

print(sess.run(hello).decode())
点击查看更多相关文章

转载注明原文:python – TensorFlow中实际输出之前的额外’b’ - 乐贴网