Reputation: 1
sudo python yantest.py 255,255,0
who = sys.argv[1]
print sys.argv[1]
print who
print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)
yanon(strip, Color(who))
output from above is
255,255,0
255,255,0
Number of arguments: 2 arguments.
Argument List: ['yantest.py', '255,255,0']
Traceback (most recent call last):
File "yantest.py", line 46, in <module>
yanon(strip, Color(who))
TypeError: Color() takes at least 3 arguments (1 given)
Segmentation fault
How do I use the variable "who" inside the Color function?
Ive tried ('who'), ("who") neither of which work either.
Upvotes: 0
Views: 106
Reputation: 4071
who is a string. I don't know what type of variable color should get but probably int. You should split who string to 3 sub strings by "," and convert each one to int or whatever it should be.
Upvotes: 0
Reputation: 124
TypeError: Color() takes at least 3 arguments (1 given)
Error means that you should pass 3 arguments but you only pass 1 argument. Here are two ways to implement:
color_r = sys.argv[1]
color_g = sys.argv[2]
color_b = sys.argv[3]
yanon(strip, Color(color_r, color_g, color_b))
Run script as:
sudo python yantest.py 255 255 0
OR
who = sys.argv[1].split(',')
yanon(strip, Color(who[0], who[1], who[2]))
Run script as:
sudo python yantest.py 255,255,0
And you should care about the type of argument!
Upvotes: 0