タイムスタンプ行ごとにデータを抽出しているのですが、重複したデータが1つと言う扱いになってしまいます。対処方法を知りたいです。
以下の形で記述しています。
def logparser(filepath): """ ログファイルからデータを抽出 """ datastore = defaultdict(dict) with open(filepath) as f: for textline in f.readlines(): try: textline = textline.rstrip('\n') items = textline.split() timestamp = textline[:23] datastore[timestamp]['タイムスタンプ'] = timestamp if items[-2] == 'INFO:': datastore[timestamp]['リクエスト内容'] = textline.split('INFO: ')[1] if 'type' in items: datastore[timestamp]['type'] = textline.split('type = ')[1] except: pass return datastore
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。