Datetime.strptime - NonType error on second use
I'm having an odd issue when converting date formats using datetime, I'm running on Windows the Oct. 17th build, but happens on any other pre-Eden nightly I've tested on

In Dharma I believe it is running Python 2.4 so is not affected as the strptime attribute is in the 'time' library, did not get moved to datetime until 2.5

Basically I have the following quick function to convert a date to a different format, and I'm executing it in a small tester video addon:

from datetime import datetime
import time
    def convert_date(self, string, in_format, out_format):
        ''' Helper method to convert a string date in format dd MMM YYYY to YYYY-MM-DD '''
        #Legacy check, Python 2.4 does not have strptime attribute, instroduced in 2.5
        if hasattr(datetime, 'strptime'):
            strptime = datetime.strptime
            strptime = lambda date_string, format: datetime(*(time.strptime(date_string, format)[0:6]))
            a = strptime(string, in_format).strftime(out_format)
        except Exception, e:
            print 'Date conversion failed: %s' % e
            return None
        return a

I have the legacy check in for Dharma users, I can assure you that piece of code is not causing any issues

Doing a quick call to this method to return just the year from a given date works fine:

year = convert_date('2011-01-01', '%Y-%m-%d', '%Y')

But if I run the addon a 2nd time (the only thing it does is executes this code) I get the following error:

attribute of type 'NoneType' is not callable

I need to shut down xbmc and restart it for it to work again, then on the 2nd run it fails with this error.. I can reproduce this time and time again. I can call this method a hundred times over on the first run and will work fine. It's always on the 2nd time launching the addon

If I revert back to Dharma 10.1 it will use time.strptime and works perfect

Any ideas? This code works perfectly fine in Python Idle 2.7 no matter how many times I run it..

Messages In This Thread
Datetime.strptime - NoneType error on second use - by Eldorado - 2011-10-21, 19:52
[No subject] - by takoi - 2011-10-23, 12:15
[No subject] - by Eldorado - 2011-10-24, 16:49
Same issue - by shanemeagher - 2011-12-20, 18:21
[No subject] - by Eldorado - 2011-12-20, 18:25
RE: - by Leopold - 2012-10-12, 15:36
[No subject] - by k_zeon - 2011-12-22, 15:29

Logout Mark Read Team Forum Stats Members Help
Datetime.strptime - NonType error on second use1
This forum uses Lukasz Tkacz MyBB addons.