I want to pass some integer values into an array via sys.argv, but I get a TypeError. how can I pass integers into my array, from the argv list? Must I do an explicit conversion?
#!/usr/bin/python
from array import array
import serial, sys
ser = serial.Serial('/dev/ttyACM0', 9600)
a=array('i',(0 for i in range(1, 3)))
a.append(sys.argv[1])
a.append(sys.argv[2])
a.append(sys.argv[3])
print(a.range(0-2))
Here is the Error:
$ ./a.py 2 3 4
Traceback (most recent call last):
File "./a.py", line 8, in <module>
a.append(sys.argv[1])
TypeError: an integer is required
I get that array('i') is an array of ints, and that sys.argv is a list item. I just dont know how to get sys.argv to become an int.