Skip to content
Advertisement

execute code only while sys.argv[1] exist

I have this code:

JavaScript

and i want execute this piece of code only while sys.argv[1] is exist:

JavaScript

if i only start the program without an arguments (python program.py) it’s print this text:

JavaScript

I tried “if sys.argv == 1” but doesnt worked.

Any solutions? Thanks

Advertisement

Answer

JavaScript

Now your program will terminate entirely if the user didn’t supply any arguments, rather than continuing and raising an exception.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement