datetime.datetime.strptime不存在于Python 2.4.1中 [英] datetime.datetime.strptime not present in Python 2.4.1
问题描述
我们的团队在某些情况下需要使用Python 2.4.1。 Python 2.4.1中 datetime.datetime
模块中不存在 strptime
Our team is required to use Python 2.4.1 in certain circumstances. strptime
is not present in the datetime.datetime
module in Python 2.4.1:
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.strptime
Traceback (most recent call last):
File "<string>", line 1, in <fragment>
AttributeError: type object 'datetime.datetime' has no attribute 'strptime'
到2.6:
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.strptime
<built-in method strptime of type object at 0x1E1EF898>
在打字时,我发现它在2.4.1的时间模块中:
While typing this up, I found it in the time module of 2.4.1:
Python 2.4.1 (#65, Mar 30 2005, 09:16:17) [MSC v.1310 32 bit (Intel)]
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.strptime
<built-in function strptime>
我认为 strptime
点?检查这样的东西是最好的方法。我试过看看python的发行历史,但找不到任何东西。
I take it that strptime
moved at some point? What's the best way to check things like this. I tried looking through python's release history but couldn't find anything.
推荐答案
请注意, strptime
仍然在
时间
模块中,即使是2.7.1,以及 datetime
Note that strptime
is still in the time
module, even as of 2.7.1, as well as in datetime
.
然而,如果你看看最新版本中的datetime 文档,您将在 strptime
下看到:
If, however, you look at the documentation for datetime in a recent version, you will see this under strptime
:
这相当于
datetime(*(time.strptime(date_string,format)[0:6]))
,所以你可以使用该表达式。请注意,同一条目也表示2.5版本新增。
so you can use that expression instead. Note that the same entry also says "New in version 2.5".
这篇关于datetime.datetime.strptime不存在于Python 2.4.1中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!