problem with eval and time

Wincent ronggui.huang at gmail.com
Tue Nov 6 05:29:47 CET 2012


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... at 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.



More information about the Python-list mailing list