[Tutor] Fwd: "ImportError: _strptime not supported"

Marc Tompkins marc.tompkins at gmail.com
Wed Oct 3 00:33:15 CEST 2012


Forgot to send to the list.  Grrr.

---------- Forwarded message ----------
From: Marc Tompkins <marc.tompkins at gmail.com>
Date: Tue, Oct 2, 2012 at 3:32 PM
Subject: Re: [Tutor] "ImportError: _strptime not supported"
To: akleider at sonic.net


On Tue, Oct 2, 2012 at 3:19 PM, <akleider at sonic.net> wrote:

>
> The following code was recently suggested as an example of how the
> datetime module could be used to solve a problem.  Not having access to
> Python at work, I found
> http://pythontutor.com/visualize.html
> thinking it would allow me to "play with Python" when I have a free
moment.
>
> from datetime import datetime
> start_date = datetime(year=2012, month=11, day=3)
> print(start_date)
>
> datestring = '10/11/2012'
> experiment_date = datetime.strftime(datestring, '%d/%m/%Y')
> print(experiment_date)
>
> if experiment_date > start_date:
>     print("Experiment_date comes after start_date.")
> else:
>     print("Expriment_date does not come after start_date.")
>
> Does not complete because of:
>
> "ImportError: _strptime not supported"
>
> At first I thought perhaps strptime was a Python3 feature but both v2.7
> and v3.2 result in the same ImportError.
> Is the problem with http://pythontutor.com/visualize.html
> ?
>
> Also, the leading underscore in the error message puzzles me.
>
> According to
> http://docs.python.org/library/datetime.html
> """classmethod datetime.strptime(date_string, format)"""
> strptime should work.


I went to visualize, and pasted in your code; I don't get that ImportError.
 Instead, I get

> TypeError: descriptor 'strftime' requires a 'datetime.date' object but
> received a 'str'

on this line:

>  experiment_date = datetime.strftime(datestring, '%d/%m/%Y')


I really have no idea where your ImportError came from, especially since
the code you've posted doesn't explicitly call strptime.  I suspect that,
yes, it was a problem on the "visualize" site, and that they've cleared it
up now.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121002/c41c7a45/attachment.html>


More information about the Tutor mailing list