|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
MySQL results
When I run a "show tables" query on a database and do a for loop through the array all of my results contain parenthesis and single quotes. Am I doing something wrong? I used the cursor.fetchall() function and had to use strip to clean up the extra characters. I must be doing something wrong so if someone could explain why this occurred I would be greatful
|
|
#2
|
||||
|
||||
|
Could you post the code in question, as well as an example of its use? It's a little difficult to diagnose the problem otherwise.
|
|
#3
|
||||
|
||||
|
I'm guessing by "show table" that your running a query against every table at once because it souds like fetchall() is returning a tuple which contains other tuples..
Anyway i'm with telex, post your code ![]() Mark Last edited by netytan : October 19th, 2003 at 05:16 PM. |
|
#4
|
|||
|
|||
|
import MySQLdb
connection = MySQLdb.connect(user='user',passwd='pass', db='db') cursor = connection.cursor() query="SHOW TABLES" cursor.execute(query) RowNum=cursor.fetchall() for x in RowNum: print x shows up as ----------------------------- ('companies',) ('competition',) ('links',) ('notes',) what is a tupple, I have never heard that expression, is it only in python? the "show tables" should only return the tables in the database in an array, so im not exactly sure why it would have any other information. Thanks |
|
#5
|
||||
|
||||
|
a tuple is a data type similar to a list/array except that it's imutable (you can't change the values directly like you can with lists) represented by parenthesis
Anyway give this a go - all i've done with this is print x[0] - which prints out the first value of x instread of the whole thing: Code:
import MySQLdb
connection = MySQLdb.connect(user='user',passwd='pass', db='db')
cursor = connection.cursor()
query="SHOW TABLES"
cursor.execute(query)
RowNum=cursor.fetchall()
for x in RowNum:
print x[0]
Have fun, Mark. Last edited by netytan : October 19th, 2003 at 05:16 PM. |
|
#6
|
|||
|
|||
|
worked perfectly, thanks
|
|
#7
|
||||
|
||||
|
Btw, it's spelt "tuple"
![]() |
|
#8
|
||||
|
||||
|
Damn my bad spelling
i didn't think it looked right, its just turning into one of those days.. well, nights ![]() Think i need to sleep soon lol Mark |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > MySQL results |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|