0

I have python script a.py and it takes integer input I want to repeat this script with different input integers from 1 to 10. Usually I do create a1.py to a10.py with integer hard-corded but i want to run them without creating a1.py to a10.py

Edit:

I have script test.py

import sys
count = sys.argv[1]
print(count)

#I use this count value as an input for running further script

I want to run python test.py 2 after python test.py 1 finishes and so on. So I naively use this command: python test.py 1 && python test.py 2 && python test.py 3 && and so on... up to python test.py 10

Is there any short way to write this long command.

2

2 Answers 2

1

You can use sys.argv for getting parameters. And run the file passing the parameter to the function python my_file.py 10.

import sys


def run_range():
    count = sys.argv[1]
    for i in range(int(count)):
        print(i)


if __name__ == '__main__':
    run_range()

Sign up to request clarification or add additional context in comments.

Comments

0

You can do something similar to this:

def myFunc(x):
    print(f"HALLO {x}")

for x in range(0, 11):
    myFunc(x)

1 Comment

my python script is memory intensive. Hence, I cannot keep running all in one python script by looping.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.