Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32799
| References | <932c348a-2670-44f0-a38b-4fddae577a0e@googlegroups.com> <43fc26d7-50f4-470a-9d02-3b3e27271b63@nl3g2000pbc.googlegroups.com> <0963c058-5ba2-474b-8a18-6d3decb5889c@googlegroups.com> |
|---|---|
| Date | 2012-11-06 15:38 +1100 |
| Subject | Re: problem with eval and time |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3307.1352176730.27098.python-list@python.org> (permalink) |
On Tue, Nov 6, 2012 at 3:29 PM, Wincent <ronggui.huang@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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
problem with eval and time Wincent <ronggui.huang@gmail.com> - 2012-11-05 19:32 -0800
Re: problem with eval and time alex23 <wuwei23@gmail.com> - 2012-11-05 20:22 -0800
Re: problem with eval and time Wincent <ronggui.huang@gmail.com> - 2012-11-05 20:29 -0800
Re: problem with eval and time Chris Angelico <rosuav@gmail.com> - 2012-11-06 15:38 +1100
Re: problem with eval and time Dave Angel <d@davea.name> - 2012-11-05 23:42 -0500
Re: problem with eval and time Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-11-06 00:06 -0500
csiph-web