Type Error in Print Forwarding Table Method
Created by: berkeracir
Describe the bug I got type error when I tried to use print_forwarding_table method of Topology class.
Traceback (most recent call last):
File "D:/Projects/ahc/tests/testmutualexclusion.py", line 64, in <module>
main()
File "D:/Projects/ahc/tests/testmutualexclusion.py", line 34, in main
topology.print_forwarding_table()
File "D:\Projects\ahc\Ahc.py", line 329, in print_forwarding_table
print('\n'.join([''.join(['{:4}'.format(item) for item in row])
File "D:\Projects\ahc\Ahc.py", line 329, in <listcomp>
print('\n'.join([''.join(['{:4}'.format(item) for item in row])
TypeError: 'int' object is not iterable
To Reproduce
- Use
Topology().print_forwarding_table()
ortopology.print_forwarding_table()
.
Expected behavior I was expected to see forwarding table of the topology.
Modules Ahc module, Topology class, print_forwarding_table method.
Desktop:
- OS: Windows 10 (64-bit)
- Python version: 3.8.8 within Anaconda environment with PyCharm
Additional context I managed to fix the problem with the following lines:
def print_forwarding_table(self):
registry.print_components()
digits = int(math.log10(len(self.nodes) - 1) + 1) # Assuming node ids are integers and starting from 0 to n.
digitsFormat = '{:' + str(digits + 1) + '}' # +1 is for spacing character between node ids in forwarding table.
print('\n'.join([''.join([digitsFormat.format(destination) for destination in self.ForwardingTable[source]])
for source in self.ForwardingTable]))