+ 1
How do argv work here in python
So in a computer you would run a python code like this: from sys import argv 3 script, first, second, third = argv 4 5 print("The script is called:", script) 6 print("Your first variable is:", first) 7 print("Your second variable is:", second) 8 print("Your third variable is:", third And if you wanted to add arguments you would do this and it would give this output: python3.6 ex13.py first 2nd 3rd The script is called: ex13.py Your first variable is: first Your second variable is: 2nd Your third variable is: 3rd How do you add the first 2nd and 3rd arguments like in the example here ?
3 Antworten
+ 1
You are talking about command promt arguments. You can not add them in a sololearn background though, but can run your script in i.e. cmd window with desired argumets.
Note: I'd recommend to use a placeholder in variable assignment to avoid unpack errors. Something like this:
a,b,c, *_ = argv
+ 4
you should run it in terminal
like this :
python namefile.py first 2nd 3rd
0
Thank you