Python3.4 int object is not iterable - MySQLdb
<p>I'm running python3.4 and i'm trying to run a query with the MySQLdb library.</p>

<p>I've done one successful query but now I am stuck when it comes to integers in a query. Here's the code:</p>

<pre><code>                location = player_info[6]

                query2 = ("SELECT name FROM locations WHERE id=%d");
                execute = cursor.execute(query2, (location));
</code></pre>

<p>Value of the variable location is 2. I just keep getting the error:</p>

<blockquote>
  <p>File "login.py", line 75, in tryLogin
      execute = cursor.execute(query2, (location));</p>
  
  <p>File "/usr/lib/python3/dist-packages/MySQLdb/cursors.py", line 195, in
  execute
      args = tuple(map(db.literal, args)) TypeError: 'int' object is not iterable</p>
</blockquote>

<p>I tried to change the %d to %s because someone said it should all be in string format but I still get the same error.</p>

<p>I have also tried changing "location" variable to simply:</p>

<p>location = 2</p>

<p>Any ideas?</p>

<pre><code>            execute = cursor.execute(query2, (location));
</code></pre>

<p>In python, <code>(location)</code> is a parenthesized expression, not a tuple.  In order to force that to be a tuple, you need to add a comma: <code>(location,)</code></p>

<pre><code>            execute = cursor.execute(query2, (location,));
</code></pre>

python mysql-python