我正在尝试从具有毫秒时间戳的日志文件中读取,然后将其插入基于“st_time”作为键的字典中。
st_time = datetime.strptime(t_str[0],"%d/%b/%Y %H:%M:%S.%f")
final_dict[st_time] = line
for key in sorted(final_dict.iterkeys()):
print "%s : %s" %(key,final_dict[key])
但我在下面得到这个错误
for key in sorted(final.iterkeys()):
TypeError: can't compare datetime.datetime to tuple
示例:来自日志文件的条目
Jul 1 03:27:12 syslog: [m_java]**[ 1/Jul/2013 03:27:12.818]**[j:[SessionThread <]^Iat com/avc/abc/magr/service/find.something(abc/1235/locator/abc;Ljava/lang/String;)Labc/abc/abcd/abcd;(bytecode:7)
t_str[0] --> ['29/Jun/2013 01:16:06.149']
st_time --> 2013-06-29 01:16:06.149000
谢谢你的帮助!