Forums

TypeError: attribute of type 'NoneType' is not callable object

Hi all,

I'm working on my python script as I'm pulling the data from the sqlite3 database. I'm trying to convert the string object to datetime object, but I have got a problem with the code as I get the error when I'm trying convert from the string object to datetime object.

The error I'm getting is: TypeError: attribute of type 'NoneType' is not callable

The error are jumping on this line:

program_startdate = datetime.datetime.strptime(str(row[2]), "%Y%m%d%H%M%S")

Here is example the results from the sqlite3 database:

20140520170000
20140520170000
20140520170000
20140520170000

20140520170000 20140520170000 20140520170000

Here is the code:

#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)
           #get the programs list
           cur.execute('SELECT channel, title, start_date, stop_date FROM programs WHERE channel="channel"')
           programList = list()
           programs = cur.fetchall()


           for row in programs:
               program = row[1].encode('ascii'), str(row[2]), str(row[3])
               #print program
               #print datetime.datetime.strptime(str(row[2]), "%Y%m%d%H%M%S")
               program_startdate = datetime.datetime.strptime(str(row[2]), "%Y%m%d%H%M%S")
               #program_endDate = datetime.datetime.strptime(str(row[3]), "%Y%m%d%H%M%S")
               programList.append(program)


               # find nearest half hour
               viewStartDate = datetime.datetime.now()
               viewStartDate -= datetime.timedelta(minutes = viewStartDate.minute % 30, seconds = viewStartDate.second)

               #convert the datetime object between start and end date
               startDelta = program_startdate - viewStartDate
               #stopDelta = program_endDate - viewStartDate
               #print startDelta, stopDelta   
               # check if you're getting the result you want
               #cellStart = self._secondsToXposition(startDelta.seconds)
           cur.close()

I'm using python version 2.6.

Can you please help me how to fix the code to get rid of the error?

Thanks in advance

Are you sure you're reading the traceback correctly? I don't see any way that that line can produce that error. What it the type of row and row[2] when you do the conversion?

No I haven't. How I can read the traceback?

the type of row is the title for the program title and the row2 is the type of timestamp when i stored the date format like 20140520170000 so I can use it to work it out with the program_endDate to find out how long each program would last for, e.g: 30 mins, 1 hour...etc.

The traceback is what Python prints when there is an error.

No, I meant what is type(row) and type(row[2]) when the error occurs?