Feb-05-2018, 08:48 AM
(Feb-01-2018, 07:35 AM)wavic Wrote: Use if/elif/else.@wavic
if parser.function_1: function_1() function_2() function_3() # etc. elif parser.function_2: function_2() function_3() # etc. # .... else: # run all or do something else. whateverOr you can put the functions to a list or tuple and iterate over them:
funcs = (function_1, function_2, function_3, function_4) if parser.function_1: _ = [function() for function in funcs] elif parser.function_2: _ = [function() for function in funcs[1:]] elif parser.function_3: _ = [function() for function in funcs[2:]] # etc.
Thanks for the reply
But the 1st one won't be good option to go with, as function calling is duplicated here.
2nd solution. Do you think listing the arguments rather than function is a good idea. just wanted to check. Though, I am not sure how i gonna do that.