0

I'm really newbie in python programming specially in tensorflow concept, I already installed tensorflow in my PC, But when I make a simple program to execute "Hello Tensorflow" there is something annoyed me, the out put always appear " b' " like this picture. Error Image and my source code like this:

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

anybody may help me to solve this problem please? I'm sorry for my bad english anyway. Thanks

Akhil Mathew
  • 1,571
  • 3
  • 34
  • 69
Oppir
  • 19
  • 3
  • 5
    Possible duplicate of [Convert bytes to a Python string](https://stackoverflow.com/questions/606191/convert-bytes-to-a-python-string) – DYZ Aug 21 '17 at 04:37
  • 2
    Possible duplicate of [What does the 'b' character do in front of a string literal?](https://stackoverflow.com/questions/6269765/what-does-the-b-character-do-in-front-of-a-string-literal) – Oguzhan Aug 21 '17 at 05:59

1 Answers1

2

In python 3 there are two types of strings.

  1. byte strings
  2. strings

byte strings are array of characters which are prefixed by b'. In order to convert byte into string one needs to decode it. byte instances have method decode that will convert the byte to normal string. decode method expects encoding usually 'utf-8'.

import tensorflow as tf
hello = tf.constant("Hello, TensorFlow!")
sess = tf.Session()
print(sess.run(hello).decode("utf-8"))
Mitiku
  • 5,337
  • 3
  • 18
  • 35
  • i'm already used python 3.5.2, and my problem already solved when i add .decode("utf-8") Thanks – Oppir Aug 21 '17 at 06:51