Python Forum
argument parser: to execute single function, and subsequent functions also
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
argument parser: to execute single function, and subsequent functions also
#5
(Feb-01-2018, 07:35 AM)wavic Wrote: Use if/elif/else.

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. whatever
Or 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.
@wavic
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.
Reply


Messages In This Thread
RE: argument parser: to execute single function, and subsequent functions also - by raghu - Feb-05-2018, 08:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  mutable argument in function definition akbarza 1 622 Dec-15-2023, 02:00 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,283 Dec-25-2022, 03:00 PM
Last Post: askfriends
  i want to use type= as a function/method keyword argument Skaperen 9 2,184 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  Regex - Pass Flags as a function argument? muzikman 6 3,888 Sep-06-2021, 03:43 PM
Last Post: muzikman
  Picking a function to execute palladium 1 1,710 Feb-09-2021, 04:47 PM
Last Post: deanhystad
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 7,796 Jan-17-2021, 03:02 AM
Last Post: Jeremy7
  is there a single function to confine a number between two others? Skaperen 7 3,012 Nov-28-2020, 06:10 PM
Last Post: Skaperen
  How to use a tuple as an argument of a function zarox 5 3,995 Nov-14-2020, 08:02 PM
Last Post: buran
  calling a function and argument in an input phillup7 3 2,765 Oct-25-2020, 02:12 PM
Last Post: jefsummers
  Passing argument from top-level function to embedded function JaneTan 2 2,376 Oct-15-2020, 03:50 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020