Python Forum
Passing flags to python script, through a function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing flags to python script, through a function
#5
If creating another process is unnecessary, then exposing a function that you call from the Flask app is the right idea. Have it take as an argument the list of string arguments that you then pass to the parser. Presumably, you're using argparse.ArgumentParser, whose parse_args method does let you do that (see the docs). So, in the script, you'd just pass sys.argv to that function and in your Flask app, yeah, you'd just pass a list of strings containing the values you wanted. It's just good old dependency injection.
Reply


Messages In This Thread
RE: Passing flags to python script, through a function - by ndc85430 - Apr-20-2021, 06:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems passing arguments containing spaces to bash script and then on to python kaustin 6 438 Apr-03-2024, 08:26 PM
Last Post: deanhystad
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 762 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,330 Jun-29-2023, 11:57 AM
Last Post: gologica
  passing dictionary to the function mark588 2 1,007 Dec-19-2022, 07:28 PM
Last Post: deanhystad
  Regex - Pass Flags as a function argument? muzikman 6 3,638 Sep-06-2021, 03:43 PM
Last Post: muzikman
  string function doesn't work in script ClockPillow 3 2,434 Jul-13-2021, 02:47 PM
Last Post: deanhystad
  passing php variable to python file jerald 1 2,718 Jul-07-2021, 11:46 AM
Last Post: Larz60+
  Confused with 'flags' tester_V 10 4,960 Apr-12-2021, 03:03 AM
Last Post: tester_V
  Passing argument from top-level function to embedded function JaneTan 2 2,283 Oct-15-2020, 03:50 PM
Last Post: deanhystad
  Passing List of Objects in Command Line Python usman 7 3,216 Sep-27-2020, 03:45 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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