字符串常量的打印总是附加“b”inTensorF

2024-05-15 13:02:21 发布

您现在位置:Python中文网/ 问答频道 /正文

在Windows 10上对TensorFlow r0.12(CPU)进行测试时,我发现打印出来的字符串contant最后总是带有一个“b”。python的打印是正常的。我想不出为什么来这里寻求帮助。代码如下:

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

Tags: 字符串代码importhellosessionwindowstftensorflow
1条回答
网友
1楼 · 发布于 2024-05-15 13:02:21

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

你的打印声明必须看起来像

print(sess.run(hello).decode())

相关问题 更多 >