Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python list | How to remove parenthesis,quotes and commas in my list?

From my database, I'm returning a list to be displayed into my HTML page but my list has this unwanted symbols. I tried using split() function but it wont work. How can I remove those parenthesis,commas and quotes. Thanks for you help

The output is :

[('cenomar',), ('cedula',), ('Birth Certificate',), ('Clearance',)]

I want:

 [cenomar, cedula, Birth Certificate, Clearance]

Here is my python function:

 @app.route('/')
    def search():
        conn=psycopg2.connect("dbname='forms' user='postgres' password='everboy' 
       host='localhost' port='5432'")
       cur=conn.cursor()
       cur.execute("SELECT name from form")
       rows=cur.fetchall()
       print(rows)
       return render_template("form.html",rows=rows)
like image 996
Emman Lopez Telewik Avatar asked Oct 16 '25 04:10

Emman Lopez Telewik


1 Answers

After This line: rows=cur.fetchall() add this line

rows=[i[0] for i in rows]
like image 152
Ahmad Avatar answered Oct 17 '25 21:10

Ahmad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!