How do I execute functions with multiple arguments in the terminal?

Python Methods and Functions

First, we import the sys. We have to use the argv function of the sys module to extract the arguments of the function entered on the terminal and execute the function.





Example

 # fubar.py import sys def print_funcargs (arg1, arg2, arg3): print arg1 + '' + arg2 + '' + arg3 if __name__ == "__main__": a = sys.argv [1] b = sys.argv [2] c = sys.argv [3] print_funcargs (a, b, c) print sys.argv 

On the terminal, if we write

 $ python fubar.py I adore books 



Output

 I adore books ['fubar.py',' I', 'adore',' books'] 







Tutorials