May-16-2024, 04:56 PM
This code is strange because
You can't use try without except, but you could use
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 withEnableLoop = (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 »