Newbie to python here, I am trying to use an integer as an argument for a for loop. The code I use
from sys import argv
script, numberofposts = argv
postsint = int(numberofposts)
for x in range(0,"%d" % postsint):
print 'on time'
print "number %d" % postsint
Gives me this error –
Traceback (most recent call last):
File "forarg.py", line 6, in <module>
for x in range(0,"%d" % postsint):
TypeError: range() integer end argument expected, got str.
What am I doing wrong here? I assumed that it was a syntax issue but the error seems to indicate that the for loop is expecting an integer which I attempted to force as you can see.
for x in range(postsint): # start at beginning as mgilson suggestedshould work fine. You already casted it an integer, You shouldn’t be creating a string from it