omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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()

    Pythonista
    2
    3
    3728
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jimwims
      jimwims last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • jimwims
        jimwims last edited by

        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')))

        1 Reply Last reply Reply Quote 0
        • Matthew_Murdoch187
          Matthew_Murdoch187 last edited by

          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).

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors