Whilst debugging a downloaded example script the following extract kept returning an error from the 3rd line which I could not resolve. I must confess I do not even understand how the construction between the curly brackets is supposed to work. Googling proved rather difficult.
if_stats = psutil.net_if_stats()
#remove loopback
if_stats_filtered = {key: if_stats[key] for key, stat in if_stats.items() if "loopback" not in stat.flags}
if _stats contains the following:
{'lo': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_UNKNOWN: 0>, speed=0, mtu=65536), 'wlan0': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_UNKNOWN: 0>, speed=0, mtu=1460), 'eth0': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_HALF: 1>, speed=10, mtu=1500)}
Error generated is:
if_stats_filtered = {key: if_stats[key] for key, stat in if_stats.items() if "loopback" not in stat.flags}
AttributeError: 'snicstats' object has no attribute 'flags'
Can anyone shed some light on what is happening please?
Digging deeper I think I understand why I am getting the error:
AttributeError: 'snicstats' object has no attribute 'flags'
snicstats is a namedtuple which is defined in an imported file named _common.py which forms part of psutil. My version of that script defines snicstats as follows:
snicstats = namedtuple('snicstats',
['isup', 'duplex', 'speed', 'mtu',])
It seems a newer version of _common.py at github/psutil
redefines snicstats as follows:
snicstats = namedtuple('snicstats',
['isup', 'duplex', 'speed', 'mtu', 'flags'])
I tried to upgrade psutil to the newer version but my system keeps returning that i have the most recent version.
What can I do?