Refactor parameter initialization and display

Simplified the storage of command-line arguments by refactoring how parameters are initialized in the 'limr' class. Removed redundant storage of parameters by opting to keep them as attributes instead of storing them in both attributes and a dictionary. Enhanced the parameter display function by appending the "name" attribute from the parameter dictionary, providing clearer output. This change improves code maintainability and readability, ensuring argument-related data is handled consistently throughout the class.

Resolves confusion around parameter storage as flagged in TODO comment.
This commit is contained in:
Kumi 2024-02-05 13:35:14 +01:00
parent 5f323fea96
commit a6a6705dba
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -40,10 +40,11 @@ class limr:
in_arg = json.loads(p.stdout.read().decode("utf-8")) in_arg = json.loads(p.stdout.read().decode("utf-8"))
# initialize the parameters # initialize the parameters
for key, value in in_arg.items(): for key, in in_arg.keys():
setattr(self, key, value) in_arg[key]["argument"] = []
setattr(self, key, [])
self.parsinp = in_arg # TODO: *Either* store the parameters in a dict or as attributes, not both self.parsinp = in_arg
# initialize other variables # initialize other variables
self.parvar = {} self.parvar = {}
@ -59,7 +60,7 @@ class limr:
for key in sorted(self.parsinp.keys()): for key in sorted(self.parsinp.keys()):
val = getattr(self, key) val = getattr(self, key)
if (val != []) | (allel): if (val != []) | (allel):
print("{:<5}: {:>50} {:<25}".format(key, val, self.parsinp[key])) print("{:<5}: {:>50} {:<25}".format(key, val, self.parsinp[key]["name"]))
# add parameter variation: # add parameter variation:
# key is the argument to vary # key is the argument to vary