Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:into': 0.09; 'subject:number': 0.09; 'subject:string': 0.09; 'way:': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'module?': 0.16; 'to:name:tim chase': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'import': 0.22; 'cc:addr:gmail.com': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**1': 0.23; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'tim': 0.29; 'chase': 0.31; 'subject:time': 0.33; 'subject:the': 0.34; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'how': 0.40; 'more': 0.64; 'received:50.22': 0.84 Date: Wed, 13 Aug 2014 21:16:05 -0500 From: Tim Chase To: Tim Chase Subject: Re: how to change the time string into number? In-Reply-To: <20140813210111.197005cd@bigbox.christie.dr> References: <53EC14EC.2090503@gmail.com> <20140813210111.197005cd@bigbox.christie.dr> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com Cc: python-list@python.org 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1407982655 news.xs4all.nl 2909 [2001:888:2000:d::a6]:52592 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76249 On 2014-08-13 21:01, Tim Chase wrote: > On 2014-08-14 09:46, luofeiyu wrote: > > s="Aug" > > > > how can i change it into 8 with some python time module? > > >>> import time > >>> s = "Aug" > >>> time.strptime(s, "%b").tm_mon > 8 > > works for me. Or, if you want a more convoluted way: >>> import calendar as c >>> [i for i, m in enumerate(c.month_abbr) if m == "Aug"].pop() 8 -tkc