Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32799

Re: problem with eval and time

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.055
X-Spam-Evidence '*H*': 0.89; '*S*': 0.00; 'converts': 0.07; 'python': 0.09; 'fetch': 0.09; 'accuracy,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'time.time()': 0.16; 'string': 0.17; 'wrote:': 0.17; 'integer': 0.17; '>>>': 0.18; 'thanks.': 0.21; 'received:209.85.214.174': 0.21; 'fraction': 0.22; 'subject:problem': 0.22; 'header:In-Reply-To:1': 0.25; 'easiest': 0.27; 'message-id:@mail.gmail.com': 0.27; 'convert': 0.29; 'objects': 0.29; 'seconds': 0.30; 'safely': 0.33; 'to:addr:python- list': 0.33; 'received:google.com': 0.34; 'nov': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'data.': 0.36; 'subject:with': 0.36; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'store': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'easily': 0.39; 'little': 0.39; 'header:Received:5': 0.40; 'networking': 0.60; 'easy': 0.60; 'back': 0.62; 'times': 0.63; 'information': 0.63; 'selling': 0.64; 'social': 0.69; 'lose': 0.71; '1970,': 0.84; 'compact,': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=3cib0/tdbfLNN1Wi1XJQ2Tf7UmwQRqzhrJ2ysJrRdag=; b=I7GN4C965bDQNczkPRY/u7A8WTZendrvRt+7dxuVDxB1p9b7gbk6KwlbS3RWVYU9P4 zZmIoiPnUe/E6liaYDxskeP4eUG5ThPOnxFwyeJuExJc+tznixmp10b54VQL9u4lQ3Fk H8r4U2PpSMY63UrRCPx1m9eUot+cGMSN4Xi8neVfwJcrCsfU5iU1HMvoBTBkHJJQFOT3 506dSchSNAAM4FcG8vlUbzdSAQFgmEa6ReQb1Zdp9pqNgwtxGnq44ZC1l7aWp6cVDvxX L7D3ItWlM+nsqZJhq0IgQtcDrbAxkcCA8ClyVIgDCsxOhMRpMlYJQF/pmCAsx5i9iYSC bJpA==
MIME-Version 1.0
In-Reply-To <0963c058-5ba2-474b-8a18-6d3decb5889c@googlegroups.com>
References <932c348a-2670-44f0-a38b-4fddae577a0e@googlegroups.com> <43fc26d7-50f4-470a-9d02-3b3e27271b63@nl3g2000pbc.googlegroups.com> <0963c058-5ba2-474b-8a18-6d3decb5889c@googlegroups.com>
Date Tue, 6 Nov 2012 15:38:47 +1100
Subject Re: problem with eval and time
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3307.1352176730.27098.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1352176730 news.xs4all.nl 6883 [2001:888:2000:d::a6]:34864
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:32799

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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