#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2005
    Posts
    62
    Rep Power
    10

    argh... MySQLdb and tuples...


    Hi to all:
    With this function, is there anyway to NOT get a tuple as a result?
    Code:
    	def SumIngreso(self):
    		if self.cursor not in self.error:
    			s = "SELECT SUM(ingreso) FROM LinIE"
    			self.cursor.execute(s)
    			return self.cursor.fetchone()
    I get as a result: (500.0,)
    Is there a way for getting directly a list? Because till now I have to transform the tuple to a list...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2005
    Posts
    62
    Rep Power
    10
    I know in this case isnt needed, but I do have other functions where i get more data on the resulting tuples...
  4. #3
  5. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    Code:
    return self.cursor.fetchone()[0]
    If the tuple has multiple items, do this:
    Code:
    cursor_list = []
    for item in self.cursor.fetchone():
        cursor_list.append(item)
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2005
    Posts
    62
    Rep Power
    10
    Ok, I'll finish some stuff and look at it. Thank u very much!

IMN logo majestic logo threadwatch logo seochat tools logo