>>> args = ['1996','2000'] >>> print args ['1996', '2000'] >>> intArgs = [int(x) for x in args] >>> print intArgs [1996, 2000] >>> a = intArgs[1] + 1 >>> print a 2001
...everything is fine.
But if I do this in a '.py' file....
args = getopt.getopt(sys.argv[1:], '') intArgs = [int(x) for x in args]
...I get this error...
Traceback (most recent call last):
File "./assignment6.py", line 21, in <module>
intArgs = [int(x) for x in args]
TypeError: int() argument must be a string or a number, not 'list'
I guess my question is how can I convert a list item to an integer? I have some experience with C++ and Java (in an educational setting) but I am completely new to Python


Sign In
Create Account


Back to top









