我的代码是这样的:
j=0
list1=[]
for port in portlist1:
l=[[port.getname(),port.getsize()]]
for register in port.getregisters():
j=j+1
l.append(j)
list1.append(l)
j=0
输出打印 list1 是:
[[['B', 10], 2], [['C', 25], 1], [['F', 30], 0]]
如果我想使用函数我应该做些什么改变
register.getaddress(),register.getdirection() inside 2nd for loop instead of increment j.
所以我的输出应该是:
print list1: [[['B', 10], [['1000',IN],['1',OUT]]], [['C', 25], ['v', 1001]], [['F', 30], []]]
print list1[0]: [['B', 10], [['1000',IN],['1',OUT]]
print list1[0][1]: ['1000',IN],['1',OUT]