How to keep track of numbered variables made from function call in while loop. How many are there?
<p>So I'm writing a small project using python,
But now I'm in trouble.</p>

<p>I made some code like this:</p>

<pre><code>START_BUTTONS = ("button1", "button2")
markup = types.ReplyKeyboardMarkup()
lengthof = len(START_BUTTONS)
countn = 0
while (countn &lt; lengthof):
  exec("itembtn" + str(countn) + " = types.KeyboardButton(START_BUTTONS[" + str(countn) + "])")
  countn = countn + 1
</code></pre>

<p>So, this will parse something like this (unitl the tuple ends):</p>

<pre><code>itembtn0 = types.KeyboardButton(START_BUTTONS[0])
itembtn1 = types.KeyboardButton(START_BUTTONS[1])
</code></pre>

<p>and...</p>

<p>So those variables are usable later.</p>

<p>But, my problem is here. I want to check how many of those variables are there (itembtn0 itembtn1 itembtn2 itembtn3...) and put them like this:</p>

<pre><code>markup.row(itembtn0, itembtn1, itembtn2)
</code></pre>

<p>so , if there were 5 of those, it will return something like this:
    markup.row(itembtn0, itembtn1, itembtn2, itembtn3, itembtn4)</p>

<p>Actually I have no idea for what I should write.</p>

<p>Thanks for help! &amp; Sorry for my bad english.</p>

<p>You are trying to create numbered variables, which can in all cases be replaced by an array. Try something simple instead:</p>

<pre><code>START_BUTTONS = ("button1", "button2")
markup = types.ReplyKeyboardMarkup()
itembtn = []
for btn in START_BUTTONS:
  itembtn.append(types.KeyboardButton(btn))
</code></pre>

<p>Access it with </p>

<pre><code>itembtn[0]
itembtn[1]
etc.
</code></pre>

<p>And you can know how many there are: </p>

<pre><code>len(itembtn)
</code></pre>

<p>I am not sure about your markup function, but you can pass the whole array as parameters like this:</p>

<pre><code>markup.row(*itembtn)
</code></pre>

python python-2.7