On 2021-05-26 13:53, Shreyan Avigyan wrote:
I've already given one. Since Python is dynamically typed changing a critical 
variable can cause huge instability. Want a demonstration? Here we go,

import sys
sys.stdout = None

Now what? Now how can we print anything? Isn't this a bug? There are lots of 
code out there where we need to protect things from being overwritten. Though 
I'm never telling to use constants in Python stdlib or else I could have never 
done this demonstration. :)

Actually, I've done something like that.

    import codecs
    import sys
    sys.stdout = codecs.getwriter('utf-8')(sys.stdout.detach())

This was because I was running a script from an editor and it picked up the wrong output encoding, raising an error when I tried to print characters that were outside the ASCII range. Thankfully that problem is now solved, but it was a useful workaround.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/JMOD4JJEZICZPMTCVWGYTXZMIXNOR2JS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to