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 25, 2019 in Python by Taj
• 1,080 points
11,519 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

Hope this helps!!

If you need to know more about Python, join Python online course today.

Thanks!

answered Jun 25, 2019 by Shabnam
• 930 points

Related Questions In Python

0 votes
1 answer

I want to download a file from the website by web scraping. Can anyone explain how to do this in jupyter lab (python) with an example?

Hey, Web scraping is a technique to automatically ...READ MORE

answered Apr 7, 2020 in Python by Gitika
• 65,910 points
2,075 views
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 25, 2020 in Python by MD
• 95,440 points
498 views
0 votes
5 answers

how to exit a python script in an if statement

Instead of using the normal UTF-8 encoding, ...READ MORE

answered Jul 4, 2023 in Python by bodymist
• 140 points
348,523 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
• 58,090 points
1,088 views
0 votes
1 answer
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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 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
• 930 points
5,121 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 5, 2019 in Python by Shabnam
• 930 points
1,709 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP