Jun-07-2022, 08:35 AM
(Jun-06-2022, 02:29 PM)shantanu97 Wrote:cursor.execute("SELECT * FROM [dbo].[Centroids]") while 1: # Endless loop; same as while True:. row=cursor.fetchone() if not row: break project = row[0] Latitude = row[3] Longitude = row[2] cursor.close() # Now the loop is finished. Project, Latitude, Longitude contain the values of the last row. connection.close() return (project,Latitude,Longitude,)
There are several ways to solve this.
- Use fetchall() instead of fetchone(). In this case the "while 1" is not needed at all.
- Use "yield" instead of "return". In this case the function becomes an generator.
- Use a list and append the results in the loop to this list.