DEV Community

Discussion on: How would you rewrite this Python code?

Collapse
 
cathodion profile image
Dustin King

So why do you need to hide stdout this way?

I'm just trying to keep the code clear and non-repetitive. In terms of level of effort and maintainability, if it needs to be able to optionally write to a file, breaking the inner logic out into a function as inspired by @thinkslynk is probably best.

But if it's a one-off project it might be even better to only write to stdout and pipe it to a file in the shell if needed. (Sometimes it's fun to over-engineer though.)