Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32803
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'arguments': 0.07; 'constructor': 0.07; '0))': 0.09; 'commonly': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'typeerror:': 0.09; "skip:' 30": 0.15; 'data...': 0.16; 'given)': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'there?': 0.16; 'mon,': 0.16; 'string': 0.17; '>>>': 0.18; 'all,': 0.21; 'trying': 0.21; 'import': 0.21; 'thanks.': 0.21; 'error.': 0.21; '"",': 0.22; 'subject:problem': 0.22; "i'd": 0.22; 'example': 0.23; '(most': 0.27; 'object,': 0.27; 'header:X -Complaints-To:1': 0.28; 'arguments.': 0.29; 'really,': 0.29; 'convert': 0.29; 'file': 0.32; '11,': 0.33; 'traceback': 0.33; 'url:home': 0.33; 'to:addr:python-list': 0.33; 'nov': 0.35; 'doing': 0.35; 'there': 0.35; 'received:org': 0.36; 'created': 0.36; 'but': 0.36; 'subject:with': 0.36; 'charset:us-ascii': 0.36; 'uses': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'to:addr:python.org': 0.39; 'takes': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'most': 0.61; "you've": 0.61; 'time,': 0.62; 'evaluate': 0.62; 'show': 0.63; 'dear': 0.66; '"what': 0.84; 'dennis': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
| Subject | Re: problem with eval and time |
| Date | Tue, 06 Nov 2012 00:06:30 -0500 |
| Organization | > Bestiaria Support Staff < |
| References | <932c348a-2670-44f0-a38b-4fddae577a0e@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | adsl-76-249-16-242.dsl.klmzmi.sbcglobal.net |
| X-Newsreader | Forte Agent 3.3/32.846 |
| X-No-Archive | YES |
| 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.3309.1352178382.27098.python-list@python.org> (permalink) |
| Lines | 63 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1352178382 news.xs4all.nl 6905 [2001:888:2000:d::a6]:45342 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:32803 |
Show key headers only | View raw
On Mon, 5 Nov 2012 19:32:41 -0800 (PST), Wincent
<ronggui.huang@gmail.com> declaimed the following in
gmane.comp.python.general:
> 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.
>
Well... you don't show an example of "what I want"...
> >>> import time
> >>> tstr = str(time.localtime())
Did you look at what you are doing there?
>>> import time
>>> time.localtime()
time.struct_time(tm_year=2012, tm_mon=11, tm_mday=5, tm_hour=23,
tm_min=38, tm_sec=16, tm_wday=0, tm_yday=310, tm_isdst=0)
>>> str(time.localtime())
'time.struct_time(tm_year=2012, tm_mon=11, tm_mday=5, tm_hour=23,
tm_min=40, tm_sec=22, tm_wday=0, tm_yday=310, tm_isdst=0)'
>>>
You've created a struct_time object, then turned that into a string
representation.
> >>> 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)
Now you are trying to evaluate that string representation. But the
constructor form uses a /tuple/ of values...
>>> time.struct_time((2012, 11, 5, 23, 47, 32, 0, 310, 0))
time.struct_time(tm_year=2012, tm_mon=11, tm_mday=5, tm_hour=23,
tm_min=47, tm_sec=32, tm_wday=0, tm_yday=310, tm_isdst=0)
>>>
... not a bunch of position/keyword arguments.
I'd consider it a wart -- commonly the representation is valid for
reconstructing the data...
>>> time.mktime((2012, 11, 5, 23, 47, 32, 0, 310, 0))
1352177252.0
>>> t2 = time.localtime()
>>> t2
time.struct_time(tm_year=2012, tm_mon=11, tm_mday=6, tm_hour=0,
tm_min=3, tm_sec=52, tm_wday=1, tm_yday=311, tm_isdst=0)
>>> time.mktime(t2)
1352178232.0
>>>
But really, what do you mean by "representation of time"?
>>> time.asctime()
'Tue Nov 06 00:05:39 2012'
>>>
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll 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