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,060 points
3,452 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
0 votes
1 answer

How to call an external command from Python?

Hi@akhtar, You can use the os module in ...READ MORE

answered Jun 24 in Python by MD
• 57,020 points
54 views
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,480 points
26,560 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,660 points
166 views
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 1,360 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
3,027 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
240 views