What does "sys.stdout=codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict')" do? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What does "sys.stdout=codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict')" do?

You can see more and more python codes wich are using Emojies. Using Emojis only works when you write "sys.stdout=codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict')" at the top of your code. What does it exactly? (Dont answer it enables Emojies, please)

31st Jul 2018, 7:10 PM
Tim
Tim - avatar
3 Answers
+ 11
Depending on the language, the syntax might be different, but in general, it enables the UTF-16 (btw, 16 not 8) encoding as binding for the "standard output stream" (stdout). In practice, this makes the given console render special characters, including emojis.
14th Aug 2018, 8:35 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
and what is (sys.stdout.buffer, "strict")?
15th Aug 2018, 10:10 AM
Tim
Tim - avatar
- 4
it enables emojis
1st Aug 2018, 8:00 AM
hinanawi
hinanawi - avatar