Datetime.strptime - NonType error on second use
(2016-09-16, 23:27)zbyna Wrote:
(2016-07-02, 21:29)tmelin Wrote: I also bumped into this on a Jarvis platform just now. Workaround that also worked for me:

    datetime.strptime(date_string, format)
except TypeError:
    datetime(*(time.strptime(date_string, format)[0:6]))

The same problem. Can confirm workaround. Laugh
Big thanks !!!

Now I bumped into this on a Krypton platform, workaround worked perfectly, thank you!!
Below is an alternative approach to solve the problem, if you can not modify the file that has datetime.strptime is used.

It simply overwrites the datetime.strptime method in namespace, so you dont have to modify the source file where datetime.strptime is used.

PHP Code:
import datetime
import time

#fix for datatetime.strptime returns None
class proxydt(datetime.datetime):
def __init__(self, *args, **kwargs):
super(proxydtself).__init__(*args, **kwargs)

    def strptime

datetime.datetime proxydt 
Last example didn't work for, this one works:

import datetime
import time

#fix for datatetime.strptime returns None
class proxydt(datetime.datetime):
    def __init__(self, *args, **kwargs):
        super(proxydt, self).__init__(*args, **kwargs)

    def strptime(cls, date_string, format):
        return datetime(*(time.strptime(date_string, format)[0:6]))

datetime.datetime = proxydt
from datetime import datetime
P.S. Now - 2019, topic was started in 2011. Hmm.... Awesome
Thread Rating:
  • 0 Vote(s) - 0 Average

Logout Mark Read Team Forum Stats Members Help
Datetime.strptime - NonType error on second use00