0

I'm working with an HPC where I write a bash script which executes my python_script.py job like so:

#!/bin/bash -l
#$ -l h_rt=0:00:10
#$ -l mem=1G
#$ -cwd

module load python3/3.8
python3 python_script.py

In my python_script.py I define the variables repeat, and directory like so:

repeat = 10
directory = r'User/somedir/'

I would like to be able to set these variables in my bash script, so that they overwrite these values within python_script.py and are used instead.

1 Answers1

0

The easier way is to use in your python script :

import sys
repeat = sys.argv[1]
directory = sys.argv[2]

and in your bash script

repeat="10"
directory="User/somedir/"
python3 python_script.py $repeat $directory
Alexll7
  • 26
  • 3
  • For anyone else trying this: I found everything comes through as a string (even if using repeat=10 instead of repeat='10'), so just had to fix with repeat_int = int(repeat) in the python script and then use repeat_int from there on – TheyTakingTheHobbitsToIsengard Mar 17 '22 at 11:16