problem with eval and time

alex23 wuwei23 at gmail.com
Mon Nov 5 23:22:44 EST 2012


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