2

This is to make sure the result received from tensorFlow hello-world here is fine The hello-world page

If the Python program outputs the following, then the installation is successful and you can begin writing TensorFlow programs. (If you are new to TensorFlow, see Getting Started with TensorFlow.)

>Hello, TensorFlow!

What happens actually is to receive the output:

b'Hello, TensorFlow!'

In particular it has an extra ''b'' inside which is not expected.

Community
  • 1
  • 1
user25004
  • 1,868
  • 1
  • 22
  • 47

2 Answers2

1

It shows that this is a byte string (not a string). To know the difference, have a look at this question.

In short, a string can't be directly stored on a disk directly. It has to be encoded first & converted to byte string (a sequence of bytes). It can also be decoded back to a string. So, here if you don't wish to see that extra 'b', you can use the decode() function.

Abdur Rahman
  • 1,067
  • 4
  • 10
0

The b is not a string character (it is not within the quotes) but a prefix, indicating that the string is a byte literal containing ASCII character (as opposed to the standard python3 utf-8 encoding).

See also this question.

Community
  • 1
  • 1
P-Gn
  • 23,115
  • 9
  • 87
  • 104
  • If that is what we should expect, why it is not mentioned in tensorflow getting started tutorial, as the expected output? – user25004 Apr 20 '17 at 18:48
  • They mention the result of `print(sess.run(hello))`, which should indeed be `Hello, TensorFlow!`. Yours looks rather like the output of `sess.run(hello)`. – P-Gn Apr 20 '17 at 19:24
  • No, it is still: b'Hello, TensorFlow!' – user25004 Apr 20 '17 at 19:32
  • Yes, you are right, it would need an explicit decoding to print its content as a string. Things are working as described in python 2 though, where string conventions are different. My guess is that they prefer to keep the same code for both python versions even though the output might differ slightly, as presently. – P-Gn Apr 20 '17 at 19:41
  • I see. Thank you. – user25004 Apr 20 '17 at 19:43