字符串常量的打印始终以'B'inTensorFlow附加

Sak*_*ura 29 python windows tensorflow

在Windows 10上安装了TensorFlow r0.12(CPU)的测试时,我发现打印的字符串最后总是带有'b'.python的打印是正常的.我无法弄清楚是什么原因来到这里寻求帮助.代码如下:

>>>import tensorflow as tf
>>>hello = tf.constant('Hello, TensorFlow!')
>>>sess = tf.Session()
>>>print(sess.run(hello))
b'Hello, TensorFlow!'
Run Code Online (Sandbox Code Playgroud)

kem*_*mis 44

使用,sess.run(hello).decode()因为它是一个字节串.decode方法将返回字符串.

您的print语句必须如下

print(sess.run(hello).decode())
Run Code Online (Sandbox Code Playgroud)

  • 为什么在[验证你的tensorflow安装](https://www.tensorflow.org/install/install_windows#validate_your_installation)上没有提到这一点!?(我使用3.6.2应该使用unicode`st`) (6认同)
  • `Tensor`对象没有属性`decode`,所以你的意思是'print(sess.run(hello).decode())`?这对我有用. (3认同)
  • 2018年仍未在网站上修复.谢谢@kermis (3认同)