这是我的功能:
def printSubnetCountList(countList):
print type(countList)
for k, v in countList:
if value:
print "Subnet %d: %d" % key, value
Run Code Online (Sandbox Code Playgroud)
这是通过传递给它的字典调用函数时的输出:
<type 'dict'>
Traceback (most recent call last):
File "compareScans.py", line 81, in <module>
printSubnetCountList(subnetCountOld)
File "compareScans.py", line 70, in printSubnetCountList
for k, v in countList:
TypeError: 'int' object is not iterable
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我有一个充满IP地址的列表.我想遍历列表并打印每个IP地址.当我尝试这样做时:
def printList(theList):
for item in theList:
print item
Run Code Online (Sandbox Code Playgroud)
输出看起来像这样:
['8.0.226.5']
['8.0.247.5']
['8.0.247.71']
['8.0.249.28']
['8.0.249.29']
Run Code Online (Sandbox Code Playgroud)
我已经尝试了一切,包括循环中的"print item [0]".我究竟做错了什么?