Python Forum

Full Version: Display 20 records at a time,data structure or loop
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have this problem.I need to submit 20 words separated by a comma to a web service.The words i am getting them from mysql database. I am new to python.

Is there a data structure that i can use to do the following:

1. I have 1000 records in mysql table

2. I want to use python to select and display 20 records at a time and if the records dont number 20, just display whatever is there.

My question is, is there a data structure in python that can help me do this and second ho can i construct such a loop.
You make your SQLQuery and use fetchall to get all results.
Each row in the table is normally yielded as a list.

A list looks liks this: [1,2,3,4,5,6]
To convert this list into a string, separated by commas, you can use the join method of str.

row_in_table = ['foo', 1, 'bar, 'test']
csv_row = ','.join(row_in_table)
The str literal ',' allows access with the dot to the methods. For the first time it looks a bit strange.
The join method consumes an iterable (lists, tuples, dicts, sets, etc...) and delimit each elements with a comma.