Need to call multiple scripts one by one in sequential manner from one script and need to pass command line argument to those multiple script from the common script.

0 votes

Need to call multiple scripts  one by one in sequential manner from one script and need to pass command line argument to those multiple script from the common script through them it is called.

Aug 7 in Python by bhawna
• 120 points

recategorized Aug 9 by Niroj 64 views

1 answer to this question.

0 votes

Hello @bhawna,

You can encapsulate all the logic for each script in a function, make a new file which imports all the 3 functions, and then run that script.

So if the scripts are

edureka1.py

def f1():
  ...

edureka2.py

def f2():
  ...

edureka3.py

def f3():
  ...

Then the final script()test.py which you will run is :

#!/usr/bin/python
import sys

from edureka1 import f1
from edureka2 import f2
from edureka3 import f3
print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)

from edureka1 import f1
from edureka2 import f2
from edureka3 import f3

f1(str(sys.argv[1]),....)
f2(str(sys.argv[1]),....)
f3(str(sys.argv[1]),....)

Now run above script as follows −

$ python test.py arg1 arg2 arg3...............

Hope it helps!!

Thank You!!

answered Aug 9 by Niroj
• 58,500 points

Related Questions In Python

0 votes
1 answer

What's the right way to concatenate files and appending the New Line character in Python? Text or binary mode?

It seems like you're using the wrong ...READ MORE

answered Nov 13, 2018 in Python by Anirudh
• 2,080 points

edited Dec 14, 2018 by Anirudh 276 views
0 votes
1 answer

Need a python script to login into a website but username and password are in a txt file (Selenium automation script)

I had a similar requirement. I had ...READ MORE

answered Jan 31, 2019 in Python by Omkar
• 69,030 points
2,730 views
0 votes
1 answer

Is it possible to run a function in Python using the command line?

Suppose your file name is demo.py and ...READ MORE

answered Jun 26, 2019 in Python by Neel
• 3,010 points
150 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,356 views
0 votes
0 answers
0 votes
2 answers

Is it possible to call one python script from another Python Script?

Hello,  To call one python script from another ...READ MORE

answered Jun 30 in Python by Niroj
• 58,500 points
6,270 views
0 votes
1 answer

Write code to create a list of word lengths for the words in original_str using the accumulation pattern and assign the answer to a variable num_words_list.

Hi,  num_words_list = len(original_str.split()) original_str.split() - split words in ...READ MORE

answered May 27 in Python by Niroj
• 58,500 points
901 views