Please find the below script
from sys import argv
script, contact_name, contact_no = argv
def operation()
some code goes here
Since i run this script from command line, How do i pass contact_name and contact_no to operation function? I am using python 2.7
Command line arguments are passed as an array to the program, with the first being usually the program's location. So we skip argv[0]
and move on to the other arguments.
This example doesn't include error checking.
from sys import argv
def operation(name, number):
...
contact_name = argv[1]
contact_no = argv[2]
operation(contact_name, contact_no)
Calling from command line:
python myscript.py John 5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With