Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 19th, 2003, 01:22 PM
Digital39 Digital39 is offline
VA Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Virginia/San Diego (Soon)
Posts: 48 Digital39 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 36 m 53 sec
Reputation Power: 10
Send a message via ICQ to Digital39 Send a message via AIM to Digital39 Send a message via Yahoo to Digital39
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

Reply With Quote
  #2  
Old October 19th, 2003, 03:07 PM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 513 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #3  
Old October 19th, 2003, 03:15 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #4  
Old October 19th, 2003, 04:10 PM
Digital39 Digital39 is offline
VA Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Virginia/San Diego (Soon)
Posts: 48 Digital39 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 36 m 53 sec
Reputation Power: 10
Send a message via ICQ to Digital39 Send a message via AIM to Digital39 Send a message via Yahoo to Digital39
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

Reply With Quote
  #5  
Old October 19th, 2003, 04:19 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #6  
Old October 19th, 2003, 04:29 PM
Digital39 Digital39 is offline
VA Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Virginia/San Diego (Soon)
Posts: 48 Digital39 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 36 m 53 sec
Reputation Power: 10
Send a message via ICQ to Digital39 Send a message via AIM to Digital39 Send a message via Yahoo to Digital39
worked perfectly, thanks

Reply With Quote
  #7  
Old October 19th, 2003, 05:03 PM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 513 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 38 m 37 sec
Reputation Power: 13
Btw, it's spelt "tuple"

Reply With Quote
  #8  
Old October 19th, 2003, 05:15 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > MySQL results

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap