Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sys.argv correct sintax?
#1
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
Reply
#2
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.
Reply
#3
thanks, but
it seems much more complex than writing alone
sys.argv[1]
i can't understand how to use it.
Reply
#4
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..
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 787 May-02-2023, 08:40 AM
Last Post: Gribouillis
  sys.argv method nngokturk 3 1,077 Jan-23-2023, 10:41 PM
Last Post: deanhystad
  import argv Scott 3 5,877 Apr-01-2021, 11:03 AM
Last Post: radix018
  use of sys.argv deepakkr3110 3 3,035 Nov-29-2019, 05:41 AM
Last Post: buran
  Not all data returned from sys.argv ecdhyne 2 2,751 Sep-05-2019, 08:27 PM
Last Post: buran
  Pyinstaller with Sys.Argv[] - “Failed to Execute Script”? ironfelix717 0 5,292 Aug-07-2019, 02:29 PM
Last Post: ironfelix717
  I see is that sys.argv contains character strings helenharry 2 2,752 Jan-09-2019, 11:34 AM
Last Post: DeaD_EyE
  How argv works? Philia 7 4,831 Dec-26-2018, 12:20 AM
Last Post: metulburr
  I gotta problem with making argv parameters Bozx 3 4,047 Apr-04-2017, 03:44 AM
Last Post: alicarlos13
  argv IndexError hsunteik 2 4,528 Dec-19-2016, 06:19 AM
Last Post: hsunteik

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020