Reputation: 19
I would like to reduce my code and eliminate 3 if
statements by joining together, in an if
statement, 2 variables that if printed would create the name pointing to a 3rd variable.
Currently I have 3 if
statements that look like this:
if prd.lower() not in retentions_log:
I would like to use something like:
if prd.lower() not in retentions_+prd.lower:
So every time the function is called It would construct the 3rd variable
retentions+prd.lower = retentnions_log
This is one of the functions:
retentinon_approval_log = "SOME_VALUE"
def ret_handler_log(roletype, prd, pth, fnm, location):# [retention_proc]
"""Processors. 4Writing results to file."""
if prd in retentinon_approval_log:
if approval_check(roletype, prd, pth) == False:
try:
results_o.write("some_text")
except Exception as e:
print(e)
pass
else:
yaml_dumper(roletype, prd, location)
results_o.write("some_text")
else:
yaml_dumper(roletype, prd, location)
Update I'd like to be able to construct "retentinon_approval_+prd" retentions approval being simple text and prd being "log". To construct a variable "retentinon_approval_log" that points to "some text" and dynamically generate this with different values that are being passed to this function
Upvotes: 0
Views: 73
Reputation: 11929
You may use a dictionary to build variables. Example.
d={'var1':10, 'var2':20}
d['var1'+'var2'] = d['var1'] + d['var2'] #{'var1': 10, 'var2': 20, 'var1var2': 30}
Upvotes: 1