troubleshooting Question

return a list

Avatar of Dolamite Jenkins
Dolamite JenkinsFlag for United States of America asked on
PythonScripting Languages
4 Comments1 Solution406 ViewsLast Modified:
In trying to return a list from my database and the print then rows[1],rows[2],rows[3] etc and i cant get my list to work below but when I try ab= [str(rows[2])for rows in cur.fetchall()] iot works but I cant return more that that one so I has to do it ove and ove again but cant getit to print correctly... what am I doing wrong in the first part andwhy is reutning a list in using a db like sqlite diffrerent from using a .txt ?

rows=[]
	    con = lite.connect('specialeventms.sqlite')
		
	    cur = con.cursor()
		
	     
	    cur.execute("select * from  ptrecords ")			    
	    cur.fetchall()
	    for rows in row:
	   
	    
		self.ic = rows[0]
		
		self.ln = rows[1]
		self.fn = rows[2]
		self.age = (str(rows[3]))
		self.gen = rows[4]
		self.add = rows[5]
		self.city= rows[6]
		self.state = rows[7]
		
		self.ail = rows[9]
		self.treat = rows[10]
	    return rows
		print row[1], row[2],row[3]

 a = [str(rows[1])for rows in cur.fetchall()]
ab= [str(rows[2])for rows in cur.fetchall()]
abc = [str(rows[9])for rows in cur.fetchall()]
abcd= [str(rows[10])for rows in cur.fetchall()]

print a,ab,abc, abcd
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros