You may want to look at the datetime
module. Using its date formatting functions, you can do something like this:
>>> import datetime as dt
>>> ds = '0104160F'
>>> parsed = dt.datetime.strptime(ds, "%y%m%d0F")
>>> parsed
datetime.datetime(2001, 4, 16, 0, 0)
>>> reformatted = dt.datetime.strftime(parsed, "%Y-%m-%d")
>>> reformatted
'20010416'
In your function, you can use these as follows:
def YYMMDD0FtoYYYYMMDD(date):
return dt.datetime.strftime(dt.datetime.strptime(date, "%y%m%d0F"), "%Y-%m-%d")