반응형
네트워크 장비에 접속해 그 출력을 파싱할 때 자주 필요한 기능으로 추후 빨리 찾기 위해서 기록해 놓는다.
I use this feature really frequently when parsing network devices console's output. Basically, this post is for myself.
1. None 값을 지우기 (Remove None values in list) -> filter 함수 이용 (Using filter function)
a = ['''TenGigabitEthernet1/13 unassigned YES TFTP administratively down down TenGigabitEthernet1/14 unassigned YES TFTP administratively down down TenGigabitEthernet1/19 unassigned YES NVRAM administratively down down TenGigabitEthernet1/20 unassigned YES NVRAM administratively down down TenGigabitEthernet1/21 unassigned YES NVRAM administratively down down TenGigabitEthernet1/22 unassigned
YES NVRAM administratively down down TenGigabitEthernet1/23 unassigned YES NVRAM administratively down down TenGigabitEthernet1/24 unassigned YES NVRAM administratively down down TenGigabitEthernet1/25 unassigned YES NVRAM administratively down down TenGigabitEthernet1/26 unassigned YES NVRAM administratively down down TenGigabitEthernet1/27 unassigned YES NVRAM administratively down down TenGigabitEthernet1/28 unassigned YES NVRAM administratively down down TenGigabitEthernet1/29 unassigned YES NVRAM administratively down down TenGigabitEthernet1/30 unassigned YES NVRAM administratively down down TenGigabitEthernet1/31 unassigned YES NVRAM administratively down down
TenGigabitEthernet3/6 unassigned YES NVRAM administratively down down TenGigabitEthernet3/7 unassigned YES NVRAM administratively down down TenGigabitEthernet3/8 unassigned YES NVRAM administratively down down Fo3/9 unassigned
YES NVRAM administratively down down Fo3/10 unassigned YES NVRAM administratively down down TenGigabitEthernet4/1 unassigned YES NVRAM administratively down down TenGigabitEthernet4/2 unassigned YES NVRAM administratively down down TenGigabitEthernet4/3 unassigned YES NVRAM administratively down down TenGigabitEthernet4/4 unassigned YES NVRAM administratively down down TenGigabitEthernet4/5 unassigned YES NVRAM administratively down down TenGigabitEthernet4/6 unassigned YES NVRAM administratively down down TenGigabitEthernet4/7 unassigned YES NVRAM administratively down down TenGigabitEthernet4/8 unassigned YES NVRAM administratively down down Fo4/9 unassigned YES NVRAM administratively down down Fo4/10 unassigned YES NVRAM administratively down down mgmt0 unassigned YES NVRAM administratively down down Vlan1 unassigned YES NVRAM administratively down down''']
a = a[0].split(' ')
# Remove None values
a = list(filter(None, a))
2. 특정 값을 지우기 (Remove certain values in list) -> list comprehension 이용 (Using list comprehension)
a = ['''TenGigabitEthernet1/13 unassigned YES TFTP administratively down down TenGigabitEthernet1/14 unassigned YES TFTP administratively down down TenGigabitEthernet1/19 unassigned YES NVRAM administratively down down TenGigabitEthernet1/20 unassigned YES NVRAM administratively down down TenGigabitEthernet1/21 unassigned YES NVRAM administratively down down TenGigabitEthernet1/22 unassigned
YES NVRAM administratively down down TenGigabitEthernet1/23 unassigned YES NVRAM administratively down down TenGigabitEthernet1/24 unassigned YES NVRAM administratively down down TenGigabitEthernet1/25 unassigned YES NVRAM administratively down down TenGigabitEthernet1/26 unassigned YES NVRAM administratively down down TenGigabitEthernet1/27 unassigned YES NVRAM administratively down down TenGigabitEthernet1/28 unassigned YES NVRAM administratively down down TenGigabitEthernet1/29 unassigned YES NVRAM administratively down down TenGigabitEthernet1/30 unassigned YES NVRAM administratively down down TenGigabitEthernet1/31 unassigned YES NVRAM administratively down down
TenGigabitEthernet3/6 unassigned YES NVRAM administratively down down TenGigabitEthernet3/7 unassigned YES NVRAM administratively down down TenGigabitEthernet3/8 unassigned YES NVRAM administratively down down Fo3/9 unassigned
YES NVRAM administratively down down Fo3/10 unassigned YES NVRAM administratively down down TenGigabitEthernet4/1 unassigned YES NVRAM administratively down down TenGigabitEthernet4/2 unassigned YES NVRAM administratively down down TenGigabitEthernet4/3 unassigned YES NVRAM administratively down down TenGigabitEthernet4/4 unassigned YES NVRAM administratively down down TenGigabitEthernet4/5 unassigned YES NVRAM administratively down down TenGigabitEthernet4/6 unassigned YES NVRAM administratively down down TenGigabitEthernet4/7 unassigned YES NVRAM administratively down down TenGigabitEthernet4/8 unassigned YES NVRAM administratively down down Fo4/9 unassigned YES NVRAM administratively down down Fo4/10 unassigned YES NVRAM administratively down down mgmt0 unassigned YES NVRAM administratively down down Vlan1 unassigned YES NVRAM administratively down down''']
a = a[0].split(' ')
a = [elem for elem in a if 'unassigned' not in elem]
a = [1, 2, 3, 4, 5, 6, 7]
redundant = [2, 3]
a = [elem for elem in a if elem not in redundant]
반응형
'<개인공부> - IT > [Python]' 카테고리의 다른 글
Day 2. PyQt5 (Signal and Slot) (0) | 2021.02.09 |
---|---|
Day 1. PyQt5 사용해보기 - 빈 윈도우 띄우기 그리고 이벤트 루프 (0) | 2021.02.04 |
Cisco ISE ERS API (Device Update) (2) | 2020.08.26 |
Basic usage exchangelib (MS Exchange) (0) | 2020.08.01 |
Openpyxl - Make a report template (0) | 2020.07.30 |