1234
1234

Reputation: 241

TypeError in strptime in python 3.4

I have simple function like this

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

This gives an error

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

this dose not happens if I close and open my IDE (TestComplete)

I am using python 3.4

What am'I doing wrong?

Upvotes: 2

Views: 1482

Answers (1)

1234
1234

Reputation: 241

It seems a bug in python https://bugs.python.org/issue27400

solution was

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

copied from TestComplete forum

Upvotes: 5

Related Questions