Python Forum
Count the rows to 10 and store in the list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Count the rows to 10 and store in the list
#1
Hi all,

I need your help with my current project. I am working on get_programme_info function to find the program info by search through in the database with program ids. I have got a problem with fetching the missing data from the database. I have got the program ids for BBC One that start from 3001 to 3008. For BBC Two I have the program ids that start from 3011 to 3016.

What I want to do is to count the 10 rows for each channel and if it counts less than 10, I want to create the variables program_title and program_width to store them in the list.

Here is what I want to store them in the list if it is count less than 10:

Example:

Count less than 10:

program_title = '[B]No Programme Information Available[/B]'
program_width = 691
self.program_title.append(program_title)
self.program_width.append(program_width)
Count it to 10:

program_title = '[B]' + program_title + '[/B]'
self.program_title.append(program_title)
self.program_width.append(program_width)
Here is the code:

def get_programme_info(self):
     conn = database.connect('source.db')
     cur = conn.cursor()
     self.program_id = list(range(3001,3071)]
    self.channelList = [101 BBC One S East, 102 BBC Two, 103 ITV, 104 Channel 4, 105 Channel 5, 106 Sky One, 106 Sky Living]
    start_pos = 375    # indent for first program
    count = 0

    for program_id in self.program_id:
        cur.execute('SELECT channel, title, start_date, stop_date, description FROM programs WHERE program_id=? LIMIT 10', [program_id])
        programs = cur.fetchall()
        count += 1

        for ind, row in enumerate(programs):
            channels = row[0]
            program_title = row[1]
            program_title = program_title.encode('utf-8', 'ignore')
            program_title = '[B]' + program_title + '[/B]'
            self.program_title.append(program_title)
            self.program_width.append(program_width)
I don't know how I can count it to 10 for per channel using with my current code.

Can you please show me an example how I can use to count it to 10 and it is goes less than 10 for per channel then I want to create the variables for the string and value to store them in the self list?

Thanks in advance
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Function to count words in a list up to and including Sam Oldman45 15 6,550 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  Row Count and coloumn count Yegor123 4 1,321 Oct-18-2022, 03:52 AM
Last Post: Yegor123
  store all variable values into list and insert to sql_summary table mg24 3 1,130 Sep-28-2022, 09:13 AM
Last Post: Larz60+
  For Word, Count in List (Counts.Items()) new_coder_231013 6 2,574 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
  How to get unique entries in a list and the count of occurrence james2009 5 2,961 May-08-2022, 04:34 AM
Last Post: ndc85430
  How to store the resulting Doc objects into a list named A xinyulon 1 1,893 Mar-08-2022, 11:49 PM
Last Post: bowlofred
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,629 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  count item in list korenron 8 3,435 Aug-18-2021, 06:40 AM
Last Post: naughtyCat
  Pandas DataFrame combine rows by column value, where Date Rows are NULL rhat398 0 2,109 May-04-2021, 10:51 PM
Last Post: rhat398
  list.count does not appear to function Oldman45 7 3,905 Mar-16-2021, 04:25 PM
Last Post: Oldman45

Forum Jump:

User Panel Messages

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