代码之家  ›  专栏  ›  技术社区  ›  Aptha Gowda

TensorFlow中的Hello World

  •  3
  • Aptha Gowda  · 技术社区  · 7 年前

    当我尝试在TensorFlow中运行hello world程序时 import tensorflow as tf hello = tf.constant('Hello, TensorFlow!') sess = tf.Session() print(sess.run(hello)) 我得到了不同的输出格式,即

    b'Hello, TensorFlow!'
    

    但实际输出是

    Hello, TensorFlow!
    

    这是一个错误吗?还是我可以无视? TensorFlow documentation

    1 回复  |  直到 7 年前
        1
  •  2
  •   Kenny Alvizuris    7 年前

    这与TensorFlow无关。你面临的是 byte-literal

    引用 Python 2.x documentation:

    Python 2中忽略了前缀“b”或“b”;这表明 在Python 3中,文字应该变成字节文字(例如,当代码 自动转换为2to3)。“u”或“b”前缀可以是 后跟“r”前缀。

    这个 Python 3.3 documentation 国家:

    字节文本始终以“b”或“b”作为前缀;他们生产 字节类型而不是str类型的实例。他们可能只 包含ASCII字符;数值大于等于128的字节 必须用转义符表示。

    我还建议阅读以下内容 Unicode HOWTO ,这将消除关于在Python中打印和处理字符串的许多疑问。

    推荐文章