From 6e9275edc36b9a5f95567b01ed9a82e8d53653f4 Mon Sep 17 00:00:00 2001 From: cclauss Date: Sun, 22 Oct 2017 07:41:07 +0200 Subject: [PATCH 1/2] Simplify w/ dict.get() default value, ternary if --- utils.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/utils.py b/utils.py index 8cb44e9..42d70c6 100644 --- a/utils.py +++ b/utils.py @@ -63,11 +63,7 @@ def list_all_classes_in_module(module): def parse_bool(value): - if value.lower() == 'true': - return True - elif value.lower() == 'false': - return False - return value + return {'true': True, 'false': False}.get(value..strip().lower(), value) def convert_to_ascii(data): @@ -90,13 +86,7 @@ def break_file_path(path): def is_empty(str): - if str == 0: - return True - str = str.replace("'", "") - str = str.replace("\"", "") - if len(str) == 0: - return True - return False + return str == 0 or len(str.replace("'", "").replace("\"", "")) == 0 def read_json(filename): @@ -128,10 +118,7 @@ def parse_int(value): import ast try: int_value = int(value) - if int_value != value: - return value - else: - return int_value + return int_value if int_value == value else value except: pass From 10c139a28cafce4ad38e30dd8103ac45d53b6d27 Mon Sep 17 00:00:00 2001 From: cclauss Date: Sun, 22 Oct 2017 07:42:33 +0200 Subject: [PATCH 2/2] Update utils.py --- utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.py b/utils.py index 42d70c6..2770d1f 100644 --- a/utils.py +++ b/utils.py @@ -63,7 +63,7 @@ def list_all_classes_in_module(module): def parse_bool(value): - return {'true': True, 'false': False}.get(value..strip().lower(), value) + return {'true': True, 'false': False}.get(value.strip().lower(), value) def convert_to_ascii(data):