Python Forum
Display 20 records at a time,data structure or loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Display 20 records at a time,data structure or loop
#1
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.
Reply
#2
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to display <IPython.core.display.HTML object>? pythopen 3 45,966 May-06-2023, 08:14 AM
Last Post: pramod08728
  How can I add certain elements in this 2d data structure and calculate a mean TheOddCircle 3 1,556 May-27-2022, 09:09 AM
Last Post: paul18fr
  Real time data satyanarayana 3 24,014 Feb-16-2022, 07:46 AM
Last Post: satyanarayana
  Real time Detection and Display Gilush 0 1,789 Feb-05-2022, 08:28 PM
Last Post: Gilush
  How to make for loop display on 1 Line Extra 3 1,428 Jan-12-2022, 09:29 PM
Last Post: Extra
  How to read rainfall time series and insert missing data points MadsM 4 2,180 Jan-06-2022, 10:39 AM
Last Post: amdi40
  Store variable data and display sum after 60 seconds the_dude 11 3,460 Dec-16-2021, 07:07 PM
Last Post: deanhystad
  How to measure execution time of a multithread loop spacedog 2 2,890 Apr-24-2021, 07:52 AM
Last Post: spacedog
  Appropriate data-structure / design for business-day relations (week/month-wise) sx999 2 2,805 Apr-23-2021, 08:09 AM
Last Post: sx999
Smile Set 'Time' format cell when writing data to excel and not 'custom' limors 3 6,304 Mar-29-2021, 09:36 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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