util: Don't use types as variable names + use early return
This commit is contained in:
committed by
Eduardo Almeida
parent
c77aba9cbc
commit
933e0587f6
26
utils.py
26
utils.py
@@ -16,10 +16,10 @@ def get_list_from_file(file_path, list_name):
|
||||
|
||||
'''
|
||||
|
||||
list = []
|
||||
|
||||
# Read in the file if it exists.
|
||||
if os.path.exists(file_path):
|
||||
if not os.path.exists(file_path):
|
||||
return []
|
||||
|
||||
with open(file_path, "r", encoding="utf-8") as file_in:
|
||||
|
||||
# Look for the list.
|
||||
@@ -41,10 +41,10 @@ def get_list_from_file(file_path, list_name):
|
||||
else:
|
||||
# Evaluate the list once its end is reached.
|
||||
# Make the split function only split it once.
|
||||
list = eval(list_string.split('=', 1)[1].strip())
|
||||
break
|
||||
return eval(list_string.split('=', 1)[1].strip())
|
||||
|
||||
return list
|
||||
# List name was not found
|
||||
return []
|
||||
|
||||
|
||||
def get_bool_from_file(file_path, bool_name, value_if_missing):
|
||||
@@ -57,11 +57,11 @@ def get_bool_from_file(file_path, bool_name, value_if_missing):
|
||||
'''
|
||||
|
||||
# Read in the file if it exists.
|
||||
if os.path.exists(file_path):
|
||||
with open(file_path, "r", encoding="utf-8") as file_in:
|
||||
if not os.path.exists(file_path):
|
||||
return value_if_missing
|
||||
|
||||
with open(file_path, "r", encoding="utf-8") as file_in:
|
||||
# Look for the boolean variable.
|
||||
bool_found = False
|
||||
for line in file_in:
|
||||
|
||||
# Remove any comments.
|
||||
@@ -72,13 +72,9 @@ def get_bool_from_file(file_path, bool_name, value_if_missing):
|
||||
if bool_name in line:
|
||||
# Evaluate the variable's line once it is found. Make
|
||||
# the split function only split it once.
|
||||
bool = eval(line.split('=', 1)[1].strip())
|
||||
bool_found = True
|
||||
break
|
||||
return eval(line.split('=', 1)[1].strip())
|
||||
|
||||
if bool_found:
|
||||
return bool
|
||||
else:
|
||||
# Boolean variable was not found
|
||||
return value_if_missing
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user