Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: why not datetime.strptime() ?

Reply
Thread Tools

Re: why not datetime.strptime() ?

 
 
Skip Montanaro
Guest
Posts: n/a
 
      01-07-2005

josh> Shouldn't datetime have strptime?

Sure, but it's not quite as trivial to implement as was strftime() support.
While strftime() is a C library function and thus easily called from within
the datetime C code, strptime() is implemented in Python as part of the time
module for portability (strptime(3) is not universally available). You'd
need to import the time module, call its strptime() function with the input
string and format, then use the tuple it returns to initialize a new
datetime object.

If someone wants to get their feet wet with extension module programming
this might be a good place to start. Mostly, I think nobody who has
needed/wanted it so far has the round tuits available to spend on the task.

Skip
 
Reply With Quote
 
 
 
 
Lee Harr
Guest
Posts: n/a
 
      01-08-2005
On 2005-01-07, Skip Montanaro <(E-Mail Removed)> wrote:
>
> josh> Shouldn't datetime have strptime?
>
> Sure, but it's not quite as trivial to implement as was strftime() support.
> While strftime() is a C library function and thus easily called from within
> the datetime C code, strptime() is implemented in Python as part of the time
> module for portability (strptime(3) is not universally available). You'd
> need to import the time module, call its strptime() function with the input
> string and format, then use the tuple it returns to initialize a new
> datetime object.
>



Not sure this is exactly related, but I was using datetime
the other day to make timestamps:

>>> import datetime
>>> ts = datetime.datetime.now().isoformat()
>>> ts

'2005-01-08T09:45:16.896805'


and figured there would be an easy way to reverse that.
Something along the lines of:
dt = datetime.datetime.fromisoformat(ts)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why :: ? Why not : ? Why not . ? <- less clutter ?!? Skybuck Flying C++ 16 08-25-2007 09:48 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
why why why does function not work Horace Nunley ASP .Net 1 09-27-2006 09:52 PM
Cisco 2611 and Cisco 1721 : Why , why , why ????? sam@nospam.org Cisco 10 05-01-2005 08:49 AM



Advertisments