How to get time.strptime()?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Dec 26 18:43:06 CET 2012


On Wed, 26 Dec 2012 08:33:42 -0800, Gnarlodious wrote:

> Error: AttributeError: 'module' object has no attribute '_strptime'
> 
> This problem is driving me crazy. It only happens in Python 3.3.0, while
> on my server running 3.1.3 it behaves as expected. When I try to access
> time.strptime() it errors with
> 
> AttributeError: 'module' object has no attribute '_strptime'.
[...]
> If anyone could explain why it thinks I want an underscored name maybe
> it would help.

Perhaps if you were to read the ENTIRE traceback, not just the last line, 
you will see something that hints at an explanation. Here is a similar 
error:

py> time.strptime(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.3/_strptime.py", line 494, in 
_strptime_time
    tt = _strptime(data_string, format)[0]
  File "/usr/local/lib/python3.3/_strptime.py", line 306, in _strptime
    raise TypeError(msg.format(index, type(arg)))
TypeError: strptime() argument 0 must be str, not <class 'NoneType'>


After reading the full traceback, I conclude that the time.strptime 
function calls _strptime._strptime. After importing _strptime and looking 
at the __file__ attribute, I see that it is a pure-python module. So, to 
answer your immediate question:

"explain why it [the time.strptime function] thinks I want an underscored 
name"

the answer is, it thinks you want an underscored name because you *do* 
need an underscored name. It is part of the implementation of 
time.strptime that it delegates some of the work to a private module 
_strptime.

As for why that is not available under mod_wsgi module, but is available 
when running under the normal Python environment, I have looked at the 
_strptime.py source code and nothing stands out to explain why the 
_strptime function might not be defined. So that seems like a question 
about mod_wsgi. I suggest you start here:

http://code.google.com/p/modwsgi/wiki/WhereToGetHelp

If you do get an answer, please post it here as well, so others in the 
future who stumble across this thread will see the answer.

Good luck!



-- 
Steven



More information about the Python-list mailing list