The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
MySQL results
Discuss MySQL results in the Python Programming forum on Dev Shed. MySQL results Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 19th, 2003, 01:22 PM
|
|
VA Developer
|
|
Join Date: Jun 2003
Location: Virginia/San Diego (Soon)
Posts: 48
Time spent in forums: 4 h 36 m 53 sec
Reputation Power: 10
|
|
|
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
|

October 19th, 2003, 03:07 PM
|
 |
Wacky hack
|
|
Join Date: Apr 2001
Location: London, England
Posts: 513
Time spent in forums: 1 h 38 m 37 sec
Reputation Power: 13
|
|
|
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.
|

October 19th, 2003, 03:15 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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
__________________
programming language development: www.netytan.com – Hula
Last edited by netytan : October 19th, 2003 at 05:16 PM.
|

October 19th, 2003, 04:10 PM
|
|
VA Developer
|
|
Join Date: Jun 2003
Location: Virginia/San Diego (Soon)
Posts: 48
Time spent in forums: 4 h 36 m 53 sec
Reputation Power: 10
|
|
|
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
|

October 19th, 2003, 04:19 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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.
|

October 19th, 2003, 04:29 PM
|
|
VA Developer
|
|
Join Date: Jun 2003
Location: Virginia/San Diego (Soon)
Posts: 48
Time spent in forums: 4 h 36 m 53 sec
Reputation Power: 10
|
|
|
worked perfectly, thanks
|

October 19th, 2003, 05:03 PM
|
 |
Wacky hack
|
|
Join Date: Apr 2001
Location: London, England
Posts: 513
Time spent in forums: 1 h 38 m 37 sec
Reputation Power: 13
|
|
Btw, it's spelt "tuple" 
|

October 19th, 2003, 05:15 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|