4 ms·
If only programming were that simple... if(operation_failed) make_operation_succeed();
by RedShift1 4y ago
If only programming were that simple...
if(operation_failed)
make_operation_succeed();
- FreeFull 4y agoActual Python 3 code, in case you're not convinced import os if os.isatty(1): print("stdout is a tty") else: print("stdout is not a tty") It really is that simple. Substitute the 1 for 0 when checking if stdin is a tty, and 2 if checking stderr
- SoftTalker 4y agoI've actually seen code that is basically: if (! try_thing()) if (! try_thing_again()) if (! try_thing_a_third_time()) give_up(); ... where the thing is something that should basically always work, and if it doesn't there's no good reason to expect that trying again will have a different result. The programmer who wrote this thought it was defensive coding and a good practice.
- 3836293648 4y agoThe function is literally called isatty, so it's not that far off
- sophacles 4y agoThat's very different. This is functionally checking a flag[1], and acting accordingly. There's nothing to fail or make succeed. [1] There's an ioctl involved, and it can fail for other reasons than "fd is not terminal", however all the reason for the operation to fail are good reasons to not proceed with terminal specific behavior.