0

I'm working on my python script to get the list of programs from sqlite3 database.

I want to find the list of programs from 7 channels so i can print the list of programs.

When I use this:

for program in programList:
    idx = index(str(program))

I will get an error: TypeError int object is not callable.

When I use this code:

channelList = list()

#get the channels list
cur.execute('SELECT channel FROM programs WHERE channel GROUP BY channel')

for row in cur:
    channels = row[0].encode('ascii')
    channelList.append(channels)


# set the channels text
for index in range(0, CHANNELS_PER_PAGE):
    channel = channelList[index]

    if channel is not None:
       self.getControl(4110 + index).setLabel(channel)


programList = list()

#get the programs list
cur.execute('SELECT channel, title, start_date, stop_date FROM programs 
WHERE channel')
for row in cur:
     program = row[1].encode('ascii'), str(row[2]), str(row[3])
     programList.append(program)

for program in programList:
     idx = index(str(program))

Result for ChannelList:

17:02:10 T:6400  NOTICE: 101 ABC FAMILY
17:02:10 T:6400  NOTICE: 102 CBS
17:02:10 T:6400  NOTICE: 103 CNN USA
17:02:10 T:6400  NOTICE: 105 ESPN USA
17:02:10 T:6400  NOTICE: 106 Fox News
17:02:10 T:6400  NOTICE: 107 Animal Planet
17:02:10 T:6400  NOTICE: 108 USA Network

Result for ProgramList:

17:05:58 T:5984  NOTICE: ('The Middle -  The Ditch', '20140520170000', 
'20140520173000')
17:05:58 T:5984  NOTICE: ('The Goonies', '20140520173000', '20140520200000')
17:05:58 T:5984  NOTICE: ('Pirates of the Caribbean: On Stranger Tides', 
'20140520200000', '20140520230000')
17:05:58 T:5984  NOTICE: ('The 700 Club', '20140520230000', 
'20140521000000')
17:05:58 T:5984  NOTICE: ('The Fresh Prince of Bel-Air -  Day Damn One', 
'20140521000000', '20140521003000')
17:05:58 T:5984  NOTICE: ('The Fresh Prince of Bel-Air -  Lucky Charm', 
'20140521003000', '20140521010000')
17:05:58 T:5984  NOTICE: ('The Fresh Prince of Bel-Air -  The Ethnic Tip', 
'20140521010000', '20140521013000')
17:05:58 T:5984  NOTICE: ('The Fresh Prince of Bel-Air -  The Young and the 
Restless', '20140521013000', '20140521020000')
17:05:58 T:5984  NOTICE: ('Summer Sexy With T25!', '20140521020000', 
'20140521023000')
17:05:58 T:5984  NOTICE: ('Paid Programming', '20140521023000', 
'20140521030000')
17:05:58 T:5984  NOTICE: ('The 700 Club', '20140521030000', 
'20140521040000')
17:05:58 T:5984  NOTICE: ("Shaun T's Focus T25", '20140521040000', 
'20140521043000')
17:05:58 T:5984  NOTICE: ('Sleep Better!', '20140521043000', 
'20140521050000')
17:05:58 T:5984  NOTICE: ('Joseph Prince', '20140521050000', 
'20140521053000')
17:05:58 T:5984  NOTICE: ('Life Today With James Robison -  Christine Caine 
-  FOY, MOR 1', '20140521053000', '20140521060000')
17:05:58 T:5984  NOTICE: ('Joyce Meyer: Enjoying Everyday Life', 
'20140521060000', '20140521063000')
17:05:58 T:5984  NOTICE: ('Amazing Facts Presents', '20140521063000', 
'20140521070000')
17:05:58 T:5984  NOTICE: ("That '70s Show -  Who Wants It More?", 
'20140521070000', '20140521073000')
17:05:58 T:5984  NOTICE: ("That '70s Show -  Fez Gets the Girl", 
'20140521073000', '20140521080000')
17:05:58 T:5984  NOTICE: ("That '70s Show -  Dine and Dash", 
'20140521080000', '20140521083000')
17:05:58 T:5984  NOTICE: ("That '70s Show -  Radio Daze", '20140521083000', 
'20140521090000')
17:05:58 T:5984  NOTICE: ('700 Club Special Programming', '20140521090000', 
'20140521110000')
17:05:58 T:5984  NOTICE: ('Gilmore Girls -  A Deep-Fried Korean 
Thanksgiving', '20140521110000', '20140521120000')
17:05:58 T:5984  NOTICE: ('8 Simple Rules -  Princetown Girl', 
'20140521120000', '20140521123000')
17:05:58 T:5984  NOTICE: ('8 Simple Rules -  A Very C.J. Christmas', 
'20140521123000', '20140521130000')
17:05:58 T:5984  NOTICE: ('Reba -  And the Grammy Goes To ...', 
'20140521130000', '20140521133000')
17:05:58 T:5984  NOTICE: ('Reba -  The Wall', '20140521133000', 
'20140521140000')
17:05:58 T:5984  NOTICE: ('Reba -  The Best Defense', '20140521140000', 
'20140521143000')
17:05:58 T:5984  NOTICE: ('Reba -  For Sale, Cheap', '20140521143000', 
'20140521150000')
17:05:58 T:5984  NOTICE: ('Boy Meets World -  State of the Unions', 
'20140521150000', '20140521153000')
17:05:58 T:5984  NOTICE: ('Boy Meets World -  Show Me the Love', 
'20140521153000', '20140521160000')
17:05:58 T:5984  NOTICE: ('Boy Meets World -  For Love and Apartments', 
'20140521160000', '20140521163000')
17:05:58 T:5984  NOTICE: ("Boy Meets World -  Angela's Men", 
'20140521163000', '20140521170000')
17:05:58 T:5984  NOTICE: ('The Middle -  The Cheerleader', 
'20140521170000', '20140521173000')
17:05:58 T:5984  NOTICE: ('The Middle -  The Block Party', 
'20140521173000', '20140521180000')
17:05:58 T:5984  NOTICE: ('The Middle -  The Floating Anniversary', 
'20140521180000', '20140521183000')
17:05:58 T:5984  NOTICE: ('The Middle -  The Trip', '20140521183000', 
'20140521190000')
17:05:58 T:5984  NOTICE: ('Melissa & Joey -  Right Time, Right Place', 
'20140521190000', '20140521193000')
17:05:58 T:5984  NOTICE: ("Melissa & Joey -  Don't Look Back in Anger", 
'20140521193000', '20140521200000')
17:05:58 T:5984  NOTICE: ('Melissa & Joey -  Accidents Will Happen', 
'20140521200000', '20140521203000')
17:05:58 T:5984  NOTICE: ('Baby Daddy -  Send in the Clowns', 
'20140521203000', '20140521210000')
17:05:58 T:5984  NOTICE: ('Liar Liar', '20140521210000', '20140521230000')
17:05:58 T:5984  NOTICE: ('The 700 Club', '20140521230000', 
'20140522000000')
17:05:58 T:5984  NOTICE: ('Baby Daddy -  Flirty Dancing', '20140522000000', 
'20140522003000')
17:05:58 T:5984  NOTICE: ('Baby Daddy -  Send in the Clowns', 
'20140522003000', '20140522010000')
17:05:58 T:5984  NOTICE: ("Melissa & Joey -  Don't Look Back in Anger", 
'20140522010000', '20140522013000')
17:05:58 T:5984  NOTICE: ('Melissa & Joey -  Accidents Will Happen', 
'20140522013000', '20140522020000')
17:05:58 T:5984  NOTICE: ('21 Day Fix', '20140522020000', '20140522023000')
17:05:58 T:5984  NOTICE: ("Dr. Ordon's Secret!", '20140522023000', 
'20140522030000')
17:05:58 T:5984  NOTICE: ('The 700 Club', '20140522030000', 
'20140522040000')
17:05:58 T:5984  NOTICE: ('Airbrushed Beauty', '20140522040000', 
'20140522043000')
17:05:58 T:5984  NOTICE: ("Shaun T's Focus T25", '20140522043000', 
'20140522050000')
17:05:58 T:5984  NOTICE: ('Joseph Prince', '20140522050000', 
'20140522053000')
17:05:58 T:5984  NOTICE: ('Life Today With James Robison -  Rebekah Lyons', 
'20140522053000', '20140522060000')
17:05:58 T:5984  NOTICE: ('Joyce Meyer: Enjoying Everyday Life', 
'20140522060000', '20140522063000')
17:05:58 T:5984  NOTICE: ('Time of Grace With Pastor Mark Jeske', 
'20140522063000', '20140522070000')
17:05:58 T:5984  NOTICE: ("That '70s Show -  Donna's Panties", 
'20140522070000', '20140522073000')
17:05:58 T:5984  NOTICE: ("That '70s Show -  Romantic Weekend", 
'20140522073000', '20140522080000')
17:05:58 T:5984  NOTICE: ("That '70s Show -  Kitty's Birthday (That's 
Today?!)", '20140522080000', '20140522083000')
17:05:58 T:5984  NOTICE: ("That '70s Show -  The Trials of Michael Kelso", 
'20140522083000', '20140522090000')
17:05:58 T:5984  NOTICE: ('700 Club Special Programming', '20140522090000', 
'20140522110000')
17:05:58 T:5984  NOTICE: ("Gilmore Girls -  That'll Do Pig", 
'20140522110000', '20140522120000')
17:05:58 T:5984  NOTICE: ('8 Simple Rules -  The Sub', '20140522120000', 
'20140522123000')
17:05:58 T:5984  NOTICE: ("8 Simple Rules -  C.J.'s Temptation", 
'20140522123000', '20140522130000')
17:05:58 T:5984  NOTICE: ('Reba -  The Will', '20140522130000', 
'20140522133000')
17:05:58 T:5984  NOTICE: ('Reba -  Location, Location, Location', 
'20140522133000', '20140522140000')
17:05:58 T:5984  NOTICE: ('Reba -  Your Place or Mine', '20140522140000', 
'20140522143000')
17:05:58 T:5984  NOTICE: ("Reba -  She's Leaving Home, Bye, Bye", 
'20140522143000', '20140522150000')
17:05:58 T:5984  NOTICE: ('Boy Meets World -  No Such Thing as a Sure 
Thing', '20140522150000', '20140522153000')
17:05:58 T:5984  NOTICE: ("Let's Make a Deal", '20140520170000', 
'20140520180000')
17:05:58 T:5984  NOTICE: ('Local Programming', '20140520180000', 
'20140520203000')
17:05:58 T:5984  NOTICE: ('CBS Evening News With Scott Pelley', 
'20140520203000', '20140520210000')
17:05:58 T:5984  NOTICE: ('Judge Judy Primetime', '20140520210000', 
'20140520220000')
17:05:58 T:5984  NOTICE: ('ACM Presents: An All-Star Salute to the Troops', 
'20140520220000', '20140521000000')
17:05:58 T:5984  NOTICE: ('Local Programming', '20140521000000', 
'20140521003500')
17:05:58 T:5984  NOTICE: ('Late Show With David Letterman', 
'20140521003500', '20140521013700')
17:05:58 T:5984  NOTICE: ('The Late Late Show With Craig Ferguson', 
'20140521013700', '20140521023700')
17:05:58 T:5984  NOTICE: ('Local Programming', '20140521023700', 
'20140521030000')
17:05:58 T:5984  NOTICE: ('Up to the Minute', '20140521030000', 
'20140521060000')
17:05:58 T:5984  NOTICE: ('CBS Morning News', '20140521060000', 
'20140521063000')
17:05:58 T:5984  NOTICE: ('CBS Morning News', '20140521063000', 
'20140521070000')
17:05:58 T:5984  NOTICE: ('CBS Morning News', '20140521070000', 
'20140521073000')
17:05:58 T:5984  NOTICE: ('CBS Morning News', '20140521073000', 
'20140521080000')
17:05:58 T:5984  NOTICE: ('Local Programming', '20140521080000', 
'20140521090000')
17:05:58 T:5984  NOTICE: ('CBS This Morning', '20140521090000', 
'20140521110000')
17:05:58 T:5984  NOTICE: ('Local Programming', '20140521110000', 
'20140521130000')
17:05:58 T:5984  NOTICE: ('The Price Is Right', '20140521130000', 
'20140521140000')
17:05:58 T:5984  NOTICE: ('Local Programming', '20140521140000', 
'20140521143000')
17:05:58 T:5984  NOTICE: ('The Young and the Restless', '20140521143000', 
'20140521153000')
17:05:58 T:5984  NOTICE: ('The Bold and the Beautiful', '20140521153000', 
'20140521160000')
17:05:58 T:5984  NOTICE: ('The Talk', '20140521160000', '20140521170000')
17:05:58 T:5984  NOTICE: ("Let's Make a Deal", '20140521170000', 
'20140521180000')
17:05:58 T:5984  NOTICE: ('Local Programming', '20140521180000', 
'20140521203000')
17:05:58 T:5984  NOTICE: ('CBS Evening News With Scott Pelley', 
'20140521203000', '20140521210000')
17:05:58 T:5984  NOTICE: ("Survivor -  It's Do or Die", '20140521210000', 
'20140521230000')
17:05:58 T:5984  NOTICE: ('Survivor -  Reunion Special', '20140521230000', 
'20140522000000')
17:05:58 T:5984  NOTICE: ('Local Programming', '20140522000000', 
'20140522003500')
17:05:58 T:5984  NOTICE: ('Late Show With David Letterman', 
'20140522003500', '20140522013700')
17:05:58 T:5984  NOTICE: ('The Late Late Show With Craig Ferguson', 
'20140522013700', '20140522023700')

2 Answers2

4
for index in range(0, CHANNELS_PER_PAGE):
    channel = channelList[index]

Here you use index as a variable and store integers in it.

for program in programList:
     idx = index(str(program))

Then later, you try to use that same variable expecting it to contain a function.

unholysampler
  • 17,141
  • 7
  • 47
  • 64
  • It also puzzled me how `index` could be recognized in the second for loop. Shouldn't the variable `index` be local to the first for loop, and destroyed as it exits? Or perhaps `index` is defined elsewhere in the code... – The2ndSon Jul 24 '14 at 18:04
  • @unholysampler i have already tried it but i still get the same problem as i keep getting the same error. any idea? –  Jul 24 '14 at 18:08
  • @The2ndSon: Python does create a new scope for loops. [description](http://stackoverflow.com/a/3611987/210526). The iteration variable and variable created inside the loop are not destroyed and maintain their values. – unholysampler Jul 24 '14 at 18:09
  • @user3853587: What do you mean by "it"? Your code does not define a function named `index`. What are you actually trying to do in that line? – unholysampler Jul 24 '14 at 18:11
  • @unholysampler I'm trying to find the programs from the sqlite3 database to match the 7 channels to print the list of programs from 7 channels without print the whole programs. do it make sense? –  Jul 24 '14 at 18:20
  • @user3853587: When you iterate through the database results, you are not storing the channel in the tuple you are creating for each program. You also have a where clause in your SQL that doesn't have any restrictions on it, so you will get every program every time. Changing either of these could help you solve your problem, but this is starting to move beyond the scope of this question. Feel free to make a new question focusing on this issue. – unholysampler Jul 24 '14 at 19:05
0

It looks like index is an integer number. So what your code is trying to execute is something like: 7("stringInput"), which doesn't make sense. If you wanna keep track of the index of channels you could add a counter to your for loop. Something like:

index = 0
for program in programList:
    index += 1

But note that outside this loop, it's value will be that of when it exits the loop, aka the total number of programs.

The2ndSon
  • 307
  • 2
  • 7
  • thank you very much for this, how i can print the list of programs using the index variable? –  Jul 24 '14 at 18:10
  • `print programList[index]`, although the way for-loops work in python is that they behave like for-each loops. You could simply print out `print program` and that will output the elements in the `programList` – The2ndSon Jul 24 '14 at 18:13
  • thank you, I have tried it but it will print the whole list of programs without finding the same rows as the channels. how i can print the list of the programs in the same row as the channels using the channel variable? –  Jul 24 '14 at 18:18