Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Problem with strptime()
-
I have a script which uses datetime.strptime(). It runs fine on my desktop both in IDLE and as a normal Python program. In Poythonista, I get the error message "TypeError: attribute of type 'NoneType' is not callable." Any suggestion as to where I am going wrong? Tnx.
-
I found a solution on the web which I am posting in case anybody else has the same problem. The first line below is the one that returned the error. The second line is a workaround that (so far) seems to be working.
obstimedt = datetime.strptime(obstime, '%b %d %Y, %I:%M %p')
obstimedt = datetime.fromtimestamp(time.mktime(time.strptime(obstime, '%b %d %Y, %I:%M %p')))
-
I encountered the same problem. After struggling to get either datetime.strptime or time.strptime to work consistently without error I gave up and downloaded dateutil.
The dateutil module also has the benefit that you shouldn't need to work out the format string. Assuming that dateutil supports your date format your example code could be written as:
from dateutil import parser
obstimedt = parser.parse(obstime)
If you're interested in using dateutil then you can download it using this script: https://gist.github.com/4026516 (note that this script creates a 'temp' and a 'dateutil' directory alongside your Pythonista scripts - although the 'temp' directory gets deleted after download).