On 2021-05-26 at 12:53:32 -0000, Shreyan Avigyan email@example.com 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. :)
Now what? Now how can we print anything?
(I'm sure other languages allow programs to close stdout, but C has come up in this thread before.)
There are a handful of real use cases for closing (or otherwise changing) stdout; e.g., background/daemon processes, programs that operate exclusively in a graphical environment.