2011-10-21, 19:52
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:
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:
But if I run the addon a 2nd time (the only thing it does is executes this code) I get the following error:
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..
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:
Code:
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
else:
strptime = lambda date_string, format: datetime(*(time.strptime(date_string, format)[0:6]))
try:
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:
Code:
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:
Code:
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..