The Python Oracle

How can this code print Hello World without any print statement

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Life in a Drop

--

Chapters
00:00 How Can This Code Print Hello World Without Any Print Statement
01:27 Accepted Answer Score 14
01:44 Thank you

--

Full question
https://stackoverflow.com/questions/3140...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python

#avk47



ACCEPTED ANSWER

Score 14


The answer to the question as written: The code avoids a print statement by os.write()ing to stdout's file descriptor, which is 1:

getattr(__import__("os"), "write")(1, "Hello world!\n")

The rest of the explanation is detailed at https://benkurtovic.com/2014/06/01/obfuscating-hello-world.html. Instead of a summary here, just read the original!