def add(a,b):
return a+b
I made python function at vsc and I want to execute that function in terminal like
add(2,3)
But if so there is an error like bash: syntax error near unexpected token `2,3′
I think the matter of path of terminal but I do not know what to do
I have tried something related to path of terminal but IDK what is matter
2
Answers
You need to save the file with the function, then run the function through the command line using
python3 -c
I created a file sample.py with your function
and I ran the following command from the command-line terminal.
and the output was
Note that, I am using Linux, that’s why it is
python3
, for windows, you need to usepython
only.If you want to run your function from the command line a lot, it may be cleanest to make it an executable script. On Linux:
Make sure the script is executable:
Now you can run it from the terminal:
If you are going to make it more complex, I recommend checking out argparse. It’s more powerful than
argv
.