Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Endless printing of a table
#1
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
Reply
#2
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.
Reply
#3
I've solved the issue now but thanks for your reply
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop Xeno 2 1,054 Sep-19-2022, 02:32 AM
Last Post: Xeno
  Where's the endless loop? Mark17 14 3,809 Oct-04-2021, 06:54 PM
Last Post: Mark17
  while with try and except gets stuck in an endless loop? pcarra 3 4,655 Mar-27-2019, 07:50 PM
Last Post: pcarra
  Printing lists in a table, rows and columns randy_shooflay 6 6,331 Sep-05-2018, 07:59 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020