how to use for loop to iterating url index to collect the data
<p>I am a newbie in python. I want to write a for loop to iterate the index in order to pull the data. </p>

<p>Here is my code:</p>

<pre><code>url90=[]
for i in range(-90,0):
 url90.append('http://staging.foglogic.com/api/v1/index.php/accounts/34/reports/bcjobs?cmd=json&amp;datestr=today&amp;**index=i**&amp;filter={}&amp;filterOverride=0&amp;su=1')
</code></pre>

<p>I want index=i which from range(-90,0), however the python consider my i as  a string instead of a integer. </p>

<p>my result give me 90 identical url :</p>

<pre><code>'http://staging.foglogic.com/api/v1/index.php/accounts/34/reports/bcjobs?cmd=json&amp;datestr=today&amp;index=i&amp;filter={}&amp;filterOverride=0&amp;su=1'
</code></pre>

<p>Is there anyone can help me to solve the problem?</p>

<p>Thank you!</p>

<p>If you think that <code>i</code> variable will automatically be used in the string used to populate the list, you are wrong. It does not work that way. Use <code>.format</code>:</p>

<pre><code>url90=[]
for i in range(-90,0):
    url90.append('http://staging.foglogic.com/api/v1/index.php/accounts/34/reports/bcjobs?cmd=json&amp;datestr=today&amp;index={0}&amp;filter={{}}&amp;filterOverride=0&amp;su=1'.format(i))
print("\n".join(url90))
</code></pre>

<p>See <a href="http://ideone.com/0isAAv" rel="nofollow">Python demo</a></p>

<p>Note that literal <code>{</code> and <code>}</code> in the format string must be doubled (see <code>index={0}</code>). The <code>{0}</code> is a placeholder for the <code>i</code> variable (see <code>filter={{}}</code>) that is the first and only argument to the method.</p>

python string for-loop