A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/340817.html below:

parsing a date

parsing a dateKalle Anke skromta at gmail.com
Sat Sep 24 11:41:48 EDT 2005
On Sat, 24 Sep 2005 16:06:06 +0200, Peter Hansen wrote
(in article <04OdncFaFO3RwKjenZ2dnUVZ_s6dnZ2d at powergate.ca>):

> Kalle Anke wrote:
>> On Fri, 23 Sep 2005 23:01:18 +0200, Larry Bates wrote:
>> 
>>> but I'm not sure it is "better".  I guess it depends
>>> on what you want to do with them after parsing.
>> 
>> Sorry, I should have been clearer. I want to parse the date and create a 
>> 'date object' that is a part of larger object (I'm parsing a text file that 
>> represents the larger object and the date is a part of it).
>> 
>> So my question should probably be: is there a better way to parse the date 
>> and generate the 'date object' than the two step 
>> 
>> w = strptime(d,'%Y-%m-%d')
>> datetime.date( w[0], w[1], w[2] )
>> 
>> Since I'm new to many things in Python I'm trying to learn if there is a 
>> "better" way of doing things.
> 
> You're still not defining what "better" means to you, so who can say?
> 
> Perhaps you think a single line would be "better"?
> 
> datetime.date(*time.strptime(d, '%Y-%m-%d')[:3])


:-) It's not my day I think

Better (in this case) =

  + Being "pythonic"

  + Avoiding going through a second representation (the tuple)
    if there is some way to create a date object directly.

     jem


More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4