2016-11-03 77 views
0

我有這樣類型錯誤在蟒蛇strptime 3.4

import datetime  
def myfun(): 
     string_date = '2016-11-03' 
     myTime =datetime.datetime.strptime(string_date, "%Y-%m-%d") 

這給出了一個錯誤

TypeError attribute of type 'NoneType' is not callable Error location: Unit: ".....\Test" Line: 4 Column: 1

這個劑量不會,如果我關閉和打開我的IDE(TestComplete)

發生簡單的功能

我正在使用python 3.4

我在做什麼錯?

+1

您發佈工作正常的代碼複製,確保誤差在這些行。 –

+3

總是顯示完整的錯誤消息(追溯)。可以有更多有用的信息,即。產生問題的線路。 – furas

+0

請顯示完整的回溯。這段代碼對我來說運行得非常好。 – idjaw

回答

1

這似乎是一個錯誤的蟒蛇 https://bugs.python.org/issue27400

的解決辦法是

import datetime 
import time 

def myfun(): 
    string_date = "2016-11-03" 
    format = "%Y-%m-%d" 
    try: 
     res = datetime.datetime.strptime(string_date, format) 
    except TypeError: 
     res = datetime.datetime(*(time.strptime(string_date, format)[0:6])) 
    Log.Message(res) # testcompete print alternation 

從TestComplete論壇

+0

我得到了「TypeError:函數最多需要8個參數(給出9個)」( – user568021

+0

)您使用的是哪個python版本?您確定該錯誤不會從代碼中的任何其他方法觸發嗎? – Studeera