On Tue, Nov 6, 2012 at 3:29 PM, Wincent <ronggui.hu...@gmail.com> wrote:
> Thanks.
>
> I fetch data from social networking sites and want to mark the time of 
> access. I store all the information in a redis database, which converts 
> everything into strings and I need to convert those strings back to original 
> python objects when analyzing the data.

The easiest way, imho, is to store Unix times - simply the number of
seconds since 1970, as an integer or float. That can easily and safely
be turned into a string and back (floats might lose a little accuracy,
depending on how you do it, but the difference will be a small
fraction of a second).

>>> time.time()
1352176547.787
>>> time.gmtime(1352176547.787)
time.struct_time(tm_year=2012, tm_mon=11, tm_mday=6, tm_hour=4,
tm_min=35, tm_sec=47, tm_wday=1, tm_yday=311, tm_isdst=0)

Easy and unambiguous. Also compact, which may or may not be a selling point.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to