0
In the first post I shared with you my code to calculate tunnel numbers in Cisco SD-WAN. I’m a beginner in Python so I thought it would be a great learning experience to have someone experienced in Python, such as Rodrigo, take a look at the code and come up with improvements. As I like to share knowledge, I’m taking this journey with you all. Let’s get started!
You may recall that I had a function to calculate the tunnel number. It looked like this:
def calculate_tunnel_number(interface_name:str) -> int:
<SNIP>
return total_score
Rodrigo’s comment was that the function name is excellent as it is clear what the function does. However, my return statement returns total_score which is not clear what it does. It would be better to return tunnel_number which is what the function is calculating.
The next comment is that when splitting things and it is known how many pieces you have, it is better to unpack them, that is, assign the unwanted piece to a throwaway variable rather than using indexing. My code looked something like this:
interface_number = split_interface(interface_name)[1]
It would be better to do something like this:
_, interface_number = split_interface(interface_name)[1]
The first variable, a Continue reading