<p>如果我理解正确的话,你只是想在这些地方循环一下?在</p>
<p>你想要A7,A6,A5。。。?在</p>
如果_这_就是_你_想要_的_ , _一_个_简单_的_循环_可以_处理_它_ :_
<pre><code>for p in xrange(7,0, -1):
parliment = "A%d" % p
print p
</code></pre>
<p>对于其他值,类似的循环也同样有效:</p>
^{pr2}$
<p>您可以很容易地按照适当的顺序嵌套循环以生成所需的组合。啊!在</p>
<p>编辑:</p>
<p>字符串格式非常有用,下面是如何使用示例进行设置:</p>
<pre><code># Just create a string with the format specifier in it: %.4d - a [d]ecimal with a
# precision/width of 4 - so instead of 3 you'll get 0003
search_url = "http://www.europarl.europa.eu/sides/getDoc.do?type=REPORT&mode=XML&reference=A7-2010-%.4d&language=EN"
# This creates a Python generator. They're super powerful and fun to use,
# and you can iterate over them, just like a collection.
# 1 is the default step, so no need for it in this case
for number in xrange(1,190):
print search_url % number
</code></pre>
<p><a href="http://docs.python.org/library/stdtypes.html#string-formatting" rel="nofollow noreferrer">String formatting</a>接受一个带有各种说明符的字符串-您可以识别它们,因为它们中有%后跟%和一个元组,该元组包含格式字符串的参数。在</p>
<p>如果要添加年份和参数,请将字符串更改为:
<code>search_url = "http://www.europarl.europa.eu/sides/getDoc.do?type=REPORT&mode=XML&reference=A%d-%d-%.4d&language=EN"</code></p>
<p>重要的变化是:
reference=A<code>%d</code>-<code>%d</code>-<code>%.4d</code>&language=EN</p>
<p>这意味着您需要传递3个小数,如下所示:</p>
<p><code>print search_url % (parliment, year, number)</code></p>