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


Groups > comp.lang.python > #32797

Re: problem with eval and time

Newsgroups comp.lang.python
Date 2012-11-05 20:29 -0800
References <932c348a-2670-44f0-a38b-4fddae577a0e@googlegroups.com> <43fc26d7-50f4-470a-9d02-3b3e27271b63@nl3g2000pbc.googlegroups.com>
Message-ID <0963c058-5ba2-474b-8a18-6d3decb5889c@googlegroups.com> (permalink)
Subject Re: problem with eval and time
From Wincent <ronggui.huang@gmail.com>

Show all headers | View raw


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.

Best Regards

On Tuesday, November 6, 2012 12:22:44 PM UTC+8, alex23 wrote:
> On Nov 6, 1:32 pm, Wincent <ronggui.hu...@gmail.com> wrote:
> 
> > Dear all, I would like to convert tstr to representation
> 
> > of time, but encounter the following error. Is there a
> 
> > simple way to get what I want? Thanks.
> 
> >
> 
> > >>> import time
> 
> > >>> tstr = str(time.localtime())
> 
> > >>> eval(tstr)
> 
> >
> 
> > Traceback (most recent call last):
> 
> >   File "<stdin>", line 1, in <module>
> 
> >   File "<string>", line 1, in <module>
> 
> > TypeError: structseq() takes at most 2 arguments (9 given)>>> sys.version
> 
> 
> 
> The problem is that the repr of `time.struct_time` isn't its
> 
> constructor, so you won't be able to do this without parsing the
> 
> string, I believe.
> 
> 
> 
> What are you trying to achieve here? You already have a
> 
> time.struct_time object, why turn it into a string if what you want is
> 
> the object?
> 
> 
> 
> If you're wanting to pass time values around as strings, maybe
> 
> `time.strptime` will be more useful.

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