Ask Your Question
3

How can arguments be passed to a Python script within a SLURM batch script?

asked 2023-06-06 09:09:23 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-06 09:38:01 +0000

nofretete gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-06 09:09:23 +0000

Seen: 15 times

Last updated: Jun 06 '23