Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
user=matches[1]对象没有属性'_获取项目';Python错误器_Python_Regex_Parsing - Fatal编程技术网

user=matches[1]对象没有属性'_获取项目';Python错误器

user=matches[1]对象没有属性'_获取项目';Python错误器,python,regex,parsing,Python,Regex,Parsing,我的python脚本在运行时出错 ['dc:9f:db:1a:60:62'] 回溯(最近一次呼叫最后一次): 文件“search.py”,第26行,在 用户=匹配项[1] TypeError:'callable iterator'对象没有属性'\uu getitem' 我的脚本如下所示 重新导入 austins\u mac\u address=“f8:27:93:88:1c:95” dd={'f8:27:93:88:1c:95':'Austin iPhone', “dc:9f:db:1a:60:

我的python脚本在运行时出错

['dc:9f:db:1a:60:62']

回溯(最近一次呼叫最后一次):
文件“search.py”,第26行,在
用户=匹配项[1]
TypeError:'callable iterator'对象没有属性'\uu getitem'

我的脚本如下所示

重新导入

austins\u mac\u address=“f8:27:93:88:1c:95”

dd={'f8:27:93:88:1c:95':'Austin iPhone',
“dc:9f:db:1a:60:64”:“4-Ops-AP”,
“dc:9f:db:1a:60:62”:“4-TechOffice-AP”,
“dc:9f:db:1a:61:b9”:“7-SalesReception-AP”,
“dc:9f:db:1a:60:63”:“7-Marketing-AP”,
'dc:9f:db:1a:61:bd':'7-Sales-Engineers-AP',
“dc:9f:db:1a:60:f3”:“4-Dev-AP”,
‘dc:9f:db:1a:2c:dd’:‘4-Hurricane-AP’,
'24:a4:3c:02:cf:f6':'6-Meeting-AP',
‘dc:9f:db:1a:60:ef’:‘4-Lounge-AP’,
‘dc:9f:db:1a:61:ba’:‘7-QA-AP’,
“dc:9f:db:1a:60:5f”:“4-TechFloor-AP”,
“dc:9f:db:1a:2d:95”:“4-training1-AP”}

dat='[2014-07-22 10:21:06821]警告事件-[event]用户[e4:98:d6:27:4c:b6]在“频道11(ng)”上从AP[dc:9f:db:1a:60:64]漫游到AP[dc:9f:db:1a:2d:95]
aps=[]
进口稀土
对于打开的行(“server.log”):
matches=re.finditer(“([0-9a-f]{2}[:-]){5}[0-9a-f]{2})”行)
如果匹配:
macAddrs=[]
对于匹配中的匹配:
macAddrs.append(匹配组(0))
打印(macAddrs)
用户=匹配项[1]
如果(user.equals(austins\u mac\u地址)):
source=匹配项[3]

dest=matches[5]

问题在于
matches
是一个迭代器,因为这是
re.finditer
返回的。迭代器动态生成数据;它并不是同时包含在数据结构中。这就是为什么你不能马上访问它的第二个元素。迭代器被设计为只循环一次(就像您在
中对match in matches
所做的那样),而不会在任何时候访问随机元素

如果您希望能够访问诸如
匹配[1]
之类的随机元素,则需要首先循环遍历迭代器,并将其所有数据存储在另一个列表中

raw_matches = re.finditer('(([0-9a-f]{2}[:-]){5}[0-9a-f]{2})', line)
if raw_matches:
        matches = []
        for match in raw_matches:
                matches.append(match)
类似的,假设第一个对象在生成第二个对象时没有被破坏