创建列表会引发错误

时间:2016-06-02 02:09:52

标签: python dictionary indexing

我正在学习python并尝试解析并从日志的某些部分创建列表。

09 Jan 2011 11:24:02 UTC,09 Jan 2011 11:24:02 UTC,5,,,,32871237,,,Finance [triEvent] imported to [Jan:9|AOL Deal|Restricted New||Low_Val_PASS|Low_Val_PASS|Low| transId=32871237 region=US in=347 out=2308 Significance=Error category=finance Outcome=/Failure art=1382919579 cat=main deviceResponse=200 act=OBSERVED URI=/All Trans/fiance System suser=u98932 dst=10.1.1.1 fileType=text/javascript;charset=utf-8 request=https://www.dsakdjasdj.org/graphs/concepts/expect_and_var#focus=problem&mode=learn

继承我的代码以创建新列表,最终我将用它来创建词典。

path = 'D:/\TestFie'
new_list = ['transId', 'region', 'in', 'out']
new_dict = {}
val_list = []
with open( path, 'rb') as f:
    reader = csv.reader(f,delimiter=',')  
    for word in reader:
            d= word[9]
            start = d.find('transId')
            d= d[start:].split(' ')
            new = d[0].split("=")[1]
            val_list.append(new)
    print Counter(val_list)

如果我打印" new"我从trandId获取值,但该值没有附加到列表,我不断收到错误:

Error:
Traceback (most recent call last):
  File "temp.py", line 64, in <module>
    new = d[0].split("=")[1]
IndexError: list index out of range

基本上我想为日志的某些部分创建字典,其中键值对由&#34; =&#34;分隔。签名问题是URL和注释等日志的某些部分可以有&#34; =&#34;签名。

任何帮助将不胜感激。

0 个答案:

没有答案