Python Forum
Endless printing of a table - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Endless printing of a table (/thread-28914.html)



Endless printing of a table - djwilson0495 - Aug-09-2020

When I use the following code in python rather than giving me the table once it repeatedly prints it into the terminal rather than just printing once

if choice == 1:
        cursor.execute("SELECT * FROM Names") # displays the table on separate lines
        for x in cursor.fetchall():
            print(x)
        choice = int(input("Please select a choice from the list"))
I'm not sure why I'm having this problem can anyone offer any advice?

Thanks


RE: Endless printing of a table - bowlofred - Aug-09-2020

That's just a code snippet. Without seeing the rest of it, it's hard to tell what's going on. If cursor.fetchall() has lots of elements, then it's going to execute lots of print()s.


RE: Endless printing of a table - djwilson0495 - Aug-10-2020

I've solved the issue now but thanks for your reply