Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add external arguments in python script?

I want the user to provide some external arguments while calling a python script from command line, what changes I suppose to make inside my python script to add this functionality?

like image 449
Bhargav Upadhyay Avatar asked Oct 21 '25 03:10

Bhargav Upadhyay


1 Answers

I think this is what you are looking for

pass arguments in command line.

$ python test.py arg1 arg2 arg3

access it using sys.argv which gives list of arguments that you entered above

import sys

print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)
like image 148
Ajay Pal Avatar answered Oct 26 '25 18:10

Ajay Pal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!