How do argv work here in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 ?

30th Jul 2018, 10:03 PM
BananasDZN sd
BananasDZN sd - avatar
3 Answers
+ 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
31st Jul 2018, 7:27 AM
strawdog
strawdog - avatar
+ 4
you should run it in terminal like this : python namefile.py first 2nd 3rd
10th Oct 2018, 7:20 AM
metaamiri
metaamiri - avatar
0
Thank you
31st Jul 2018, 10:52 AM
BananasDZN sd
BananasDZN sd - avatar