[Tutor] how to send command line args to py script

shawn bright nephish at gmail.com
Mon Mar 12 02:23:26 CET 2007


lo there all,

i was wondering how to make a python script accept command line arguments.
i mean, i have used python scripts from the command line in linux and
passed something to it and it knows what to do.

like in a function, if i want to do something like this

def add_two_numbers(a, b):
    x = a + b
    return x

x = add_two_numbers(4,5)
print x

how could i do the same from the cli.

like python add_two_numbers.py 4 5
or maybe python add_two_numbers.py 4, 5
or even python add_two_numbers.py -a 4 -b 5

is there an easy way to do this ?

thanks


More information about the Tutor mailing list