How to call Python script from bash with an agrument?

0 votes
I want to pass an argument in my python script from my bash script, how can I do that?
Jun 24, 2019 in Python by Taj
• 1,040 points
36 views

1 answer to this question.

0 votes

Hi,

You need to call the same command that you would use within terminal to execute a python script in bash script.

For instance:

python python_script.py arg1 arg2

And to access these arguments in python you can use:

import sys
print sys.argv[0] # prints python_script.py
print sys.argv[1] # prints agr1
print sys.argv[2] # prints agr2
answered Jun 24, 2019 by Shabnam
• 920 points

Related Questions In Python

0 votes
1 answer

how to exit a python script in an if statement

This works fine for me: while True: ...READ MORE

answered Sep 19, 2018 in Python by bug_seeker
• 15,390 points
6,990 views
0 votes
1 answer

I'm using Python 2.7 to convert an XML response (from a REST call to Atlassian Fisheye) into an HTML table.

You don't have a template matching tabularQueryResult in your ...READ MORE

answered Oct 4, 2018 in Python by Priyaj
• 57,450 points
64 views
0 votes
1 answer

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

Yes it is possible. Suppose your script abc.py ...READ MORE

answered Jul 2, 2019 in Python by Arvind
• 2,980 points
73 views
0 votes
0 answers
0 votes
1 answer
0 votes
1 answer
+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 511 views
0 votes
1 answer

How to add a new Python interpreter in PyCharm?

Refer to the below screenshots: Then set a ...READ MORE

answered May 30, 2019 in Python by Shabnam
• 920 points
922 views
+1 vote
1 answer

How to check if a string is in a file, using python?

Hi, Try the below given code: with open('myfile.txt') as ...READ MORE

answered Jul 4, 2019 in Python by Shabnam
• 920 points
77 views