Python Forum

Full Version: sys.argv correct sintax?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello i want use
python3 rgb.py colore modalita
but sys.argv[1] and sys.argv[2] not work.

my code
import os, sys
from gpiozero import RGBLED
print ("Modalita:", sys.argv[2])
print ("Colore:", sys.argv[1])
# Pin
R = 11
G = 13
B = 15
rgb = RGBLED(R,G,B,False)
after this i want
rgb.color = (sys,argv[2])
and
rgb.sys.argv[1]()
example
rgb.color = (1,0,1)
rgb.on()
but i can't find correct sintax Confused
argparse is the way to go,
there's a tutorial here: https://docs.python.org/3/howto/argparse.html
It's pretty easy to use and works great.
thanks, but
it seems much more complex than writing alone
sys.argv[1]
i can't understand how to use it.
sys.argv are command line arguments that come when running the script
sys.argv[0] is always the script name and so on.
that's said it's not clear what you want to do with the arguments. Also, post example how you run it, i.e. what sys.ardv[1] and [2] are..