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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Tue, Nov 6, 2012 at 3:29 PM, Wincent wrote: > Thanks. > > I fetch data from social networking sites and want to mark the time of ac= cess. I store all the information in a redis database, which converts every= thing into strings and I need to convert those strings back to original pyt= hon 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=3D2012, tm_mon=3D11, tm_mday=3D6, tm_hour=3D4, tm_min=3D35, tm_sec=3D47, tm_wday=3D1, tm_yday=3D311, tm_isdst=3D0) Easy and unambiguous. Also compact, which may or may not be a selling point= . ChrisA