2017-09-27 58 views
0

代碼下方固定:爲什麼結果打印b'hello,Python!' ,當我使用tensorflow?

import tensorflow as tf 

hello=tf.constant("hello,Python!") 

sess=tf.Session() 

print(sess.run(hello)) 

enter image description here

當前結果下方固定:

b'hello,巨蟒」

然後截圖

所以,我該怎麼辦當前結果之前砸怪「B」?

+0

我的描述可能是有點令人費解,其實,在我跑的代碼,結果頭顯示其混淆了我很多「B」。 – DawnZhang

+0

「b」字符前綴表示'Hello,TensorFlow!'是一個[byte string](https://stackoverflow.com/questions/6224052/what-is-the-difference-between-a-string-and-一個字節的字符串) – ScouserInTrousers

回答

2

作爲每Python的2.x的documentation

'b' 或 'B' 的前綴在Python 2被忽略;它表明 文字應該成爲Python 3中的一個字節文字(例如當代碼是 自動轉換爲2to3時)。 'u'或'b'前綴可能是 ,後跟'r'前綴。

在Python 3.x的

所以

字節= B '...' 文字=八位字節(整數0和 255之間)的順

這不是真的存在,它只會被打印。這不應該在任何地方引起任何問題。

您可以嘗試decode(「utf-8」)將其轉換爲str。

對我的作品

>>> print(out) 
b'hello,Python!' 
>>> out.decode('utf-8') 
'hello,Python!' 
相關問題