Hidden in a Module
00:00
The __hello__
module is a perfect example of an Easter egg because it’s concealed. If you go to the official Python documentation, you won’t be able to find it.
00:09
For example, if you navigate to the docs.python.org and type __hello__
, it won’t show up because even though it’s in Python, it’s not documented on purpose.
00:21 But since you’re running Python locally, you can find that file and view its source code. You could also go to see Python source code on GitHub and look it up there, but probably the quickest way would be to use something like B Python, which is a cool little wrapper around the standard Python or read-eval-print loop.
00:43
And when you import something like __hello__
.
00:47
And then you use a keyboard shortcut under your core, I think the default one is F2. It will show you the source code. In here we can see we have some variable called initialized
.
01:01
We have a few classes and the main()
function,
01:06 and it turns out that these few classes aren’t completely useless because they’re actually used in the unit tests in Python, if I recall correctly.
01:15
So this module isn’t just an Easter egg, it’s actually being used by the unit tests in Python. And then we have the main()
function, which is the entry point to that module, which means that when you run this module, the way I showed it before, using Python -m
option, it will run the main()
function in here.
01:32
And it will print the Hello, World!
text on the screen.
Become a Member to join the conversation.