Python 使用datefinder提取datetime字符串
TypeError:应为字符串或字节,如object您必须尝试提取标识为日期时间字符串的字符串 您不需要Python 使用datefinder提取datetime字符串,python,regex,datefinder,Python,Regex,Datefinder,TypeError:应为字符串或字节,如object您必须尝试提取标识为日期时间字符串的字符串 您不需要re.findall,您需要告诉find_dates通过传递source=True参数返回包含日期时间和源字符串的元组: matches = list(datefinder.find_dates(str(laslogsystime[0]))) if len(matches) > 0: date = matches[0] # print(date) logging = r
re.findall
,您需要告诉find_dates
通过传递source=True
参数返回包含日期时间和源字符串的元组:
matches = list(datefinder.find_dates(str(laslogsystime[0])))
if len(matches) > 0:
date = matches[0]
# print(date)
logging = re.findall(r'(.*?)', date)[0]
print(logging)
什么是激光系统时间[0]?为什么要使用
re.findall(r'(.*?),date)
?你想实现什么?你能确定date
是str
还是bytes
?我想<代码>日期<代码>看起来像“代码>列表< /代码>或某个LasLogySyt[ 0 ]是包含该日期的列表,请检查下面的答案,如果它有效,请考虑接受(参见)。
import datefinder
from datetime import datetime
laslogsystime = "August 1990 some text May 21 2015"
matches = [src for time, src in datefinder.find_dates(laslogsystime, source=True)]
print(matches) # => ['August 1990', 'May 21 2015']