print before adding :P

python exception says that chart.id_chart.lastupdated is None.

On Sunday, November 11, 2012 11:20:04 PM UTC+1, Simon Carr wrote:
>
> so given this code then
>
> def refresh_charts():
>     import datetime
>     charts = db(db.user_chart).select()
>     for chart in charts:
>        a = chart.id_chart.lastupdated
>        print chart.id_chart.lastupdated, a + datetime.timedelta(hours=5)
>
> why do I get an error saying 
>   
> TypeError: unsupported operand type(s) for +: 'NoneType' and 
> 'datetime.timedelta'
>
>
> You can probably see what I am trying to do with the code above. How 
> should I do it?
>
> On Sunday, 11 November 2012 21:17:07 UTC, viniciusban wrote:
>>
>> Your myrecord.datetimevalue is already a python datetime.datetime field. 
>>
>>
>> On Sun, Nov 11, 2012 at 6:24 PM, Simon Carr <[email protected]> wrote: 
>> > What is the best way to create a python datetime object from a datetime 
>> > field. i.e 
>> > 
>> > import datetime 
>> > ... 
>> > my_date_time_object = datetime.datetime(myrecord.datetimevalue) 
>> > 
>> > Ultimately what I want to do is add x hours to a datetime value held in 
>> a 
>> > field and compare the new time to datetime.now to see if it is time for 
>> a 
>> > file to be updated. 
>> > 
>> > Thanks 
>> > Simon 
>> > 
>> > -- 
>> > 
>> > 
>> > 
>>
>

-- 



Reply via email to