0

I'm looking to run a bash command that runs a python file ie: "python /Users/declanmcgranahan/airflow/dags/tasks/aircall_calls_to_csv.py". But I have a variable in that python file that I want to define in the bash command. Is this possible?

declac
  • 39
  • 8

3 Answers3

2

Do you mean something like python test.py var1 var2?

Take a look at this link: Python - Command Line Arguments

This even provides options function like python test.py -a var1 -b var2

0

You can pass arguments to the bash command and then read in those arguments into required variables in the __main__ handler function. Look up argparse library on how to use it to handle provided arguments. The code in your python file should have a block:

if __name__ == "__main__":
     # use argparse to assign variables
Anuj Kumar
  • 130
  • 1
  • 9
0

you could pass a parameter to the python script on the command line, or you could set an environment variable in the script and have the script read it using getenv.

Command-line arguments: How to read/process command line arguments?

getenv: https://docs.python.org/3/library/os.html#os.getenv

jspcal
  • 50,847
  • 7
  • 72
  • 76