From 414fc60f4859fc0e30dd5c5667e75363e402b35a Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 25 Oct 2021 10:57:30 -0700 Subject: [PATCH] Reduce redundancy in get_level_by_argv with tryremove. --- voussoirkit/vlogging.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/voussoirkit/vlogging.py b/voussoirkit/vlogging.py index a832bac..28dbdeb 100644 --- a/voussoirkit/vlogging.py +++ b/voussoirkit/vlogging.py @@ -66,21 +66,23 @@ def get_level_by_argv(argv): ''' argv = argv[:] - if '--loud' in argv: + def tryremove(lst, item): + try: + lst.remove(item) + return True + except ValueError: + return False + + if tryremove(argv, '--loud'): level = LOUD - argv.remove('--loud') - elif '--debug' in argv: + elif tryremove(argv, '--debug'): level = DEBUG - argv.remove('--debug') - elif '--warning' in argv: + elif tryremove(argv, '--warning'): level = WARNING - argv.remove('--warning') - elif '--quiet' in argv: + elif tryremove(argv, '--quiet'): level = ERROR - argv.remove('--quiet') - elif '--silent' in argv: + elif tryremove(argv, '--silent'): level = SILENT - argv.remove('--silent') else: level = INFO