13

Recently I've come across this "Hello world" Python program:

>>> import __hello__
Hello world!

I wonder how it works and how to view the source code of the __hello__ module.

martineau
  • 119,623
  • 25
  • 170
  • 301
Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378

1 Answers1

14

__hello__ is a frozen module intended as a test case for frozen module support. Its source code is automatically generated by the Python freeze utility.

Aykhan Hagverdili
  • 28,141
  • 6
  • 41
  • 93
Michael Mior
  • 28,107
  • 9
  • 89
  • 113
  • The source can be found here for cpython: https://github.com/python/cpython/blob/master/Tools/freeze/hello.py – Nick is tired Jun 02 '17 at 16:33
  • 3
    @NickA: It sure looks that way at first glance, but that's actually the wrong file. Note the difference in punctuation. – user2357112 Jun 02 '17 at 17:13
  • 1
    (Or at least, it's the wrong file on Python 3. They changed it, I think in [issue 11614](http://bugs.python.org/issue11614).) – user2357112 Jun 02 '17 at 17:15
  • 1
    @user2357112 no kidding..., importing it in python 2.7 indeed has the ellipsis while python 3.4 has ! – Nick is tired Jun 02 '17 at 17:15
  • 5
    @NickA: it's the [`Tools/freeze/flag.py` file](https://github.com/python/cpython/blob/master/Tools/freeze/flag.py) that's frozen, not `hello.py`. – Martijn Pieters Aug 14 '18 at 12:35