What is the source code of the “this” module doing?

后端 未结 5 1481
旧巷少年郎
旧巷少年郎 2020-11-28 00:36

If you open a Python interpreter, and type \"import this\", as you know, it prints:

The Zen of Python, by Tim Peters

Beautiful is better

5条回答
  •  [愿得一人]
    2020-11-28 00:57

    It uses ROT13 encoding. This is used because it's a joke.

    You can also use Python functions to decode string.

    Python 2 only:

    import this
    print(this.s.decode('rot13'))
    

    Python 2 & 3:

    import codecs
    print(codecs.decode(this.s, 'rot-13'))
    

提交回复
热议问题