Posts: 4,782
Threads: 76
Joined: Jan 2018
This code is strange because
bool()
will never fail, so assuming
sys.argv
has the usual meaning, the code can raise an exception only when there are less than two command line arguments. You could replace the code with
EnableLoop = (len(sys.argv) >= 3)
When handling command line arguments it is much easier to use a module such as argparse. By scanning sys.argv, you are reinventing the wheel.
You can't use try without except, but you could use
contextlib.suppress()
with suppress(Exception):
EnableLoop = bool(sys.argv[2])
« We can solve any problem by introducing an extra level of indirection »