Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Arguments can be passed to a Python script within a SLURM batch script by including the arguments in the sbatch command. For example, if we have a Python script named "test.py" that expects two arguments, we can include the arguments in the sbatch command as follows:

#!/bin/bash
#SBATCH --job-name=test
#SBATCH --output=test.out

sbatch test.py argument1 argument2

In the Python script, we can access the arguments using the sys.argv list:

import sys

arg1 = sys.argv[1]
arg2 = sys.argv[2]

print("Argument 1:", arg1)
print("Argument 2:", arg2)

When the sbatch command is executed, the arguments "argument1" and "argument2" will be passed to the Python script, and the script will print them to the console.