반응형 전체 글213 Python f-strings (Keep updating) Python supports string formatting three different ways. 1. %-formatting 2. str.format() 3. f-strings I have used str.format() to print data so fat but I change my mind after knowing f-strings formatting. name = 'Ethan' age = 32 print (f'My name is {name} and I am {age} years old.') name = 'Ethan' age = 32 print (f'My name is {name} and I am {age} years old.') The f-strings formatting sytax is f .. 2020. 4. 4. List comprehension Overview 파이썬에서 List comprehension의 정의는 list를 간결한 방법으로 생성하는 것을 의미한다. 아래와 같은 dev_info의 문자열로 구성된 data를 list로 만들고자 하는데 list comprehension 기능을 사용하지 않으면 두 줄 정도의 코드가 필요하다. 반대로 list comprehension을 이용한다면 한 줄로 표현할 수 있다. List를 생성함과 동시에 값을 할당하는 것이다. # [List comprehension 미사용] dev_info = ' 1.1.1.1, username, password ' item_list = [] for elem in dev_info.split(','): item_list.append(elem.strip()) # [List com.. 2020. 3. 30. Python regular expression match and search methods Long story short, match and search methods can be used whether to search the beginning of the string or the entire string. Let's dig into an example. import re data = ["ESA1-XXX-XXX - Po1", "ESA1-XXX-XXX - PO1"] for elem in data: m = re.search('(Po|PO)\d', elem).group() What I want to do is to find and replace "- Po1" or "- PO1" to "(Po1)" or "(PO1)". In order to find a certain pattern, I use re.. 2020. 3. 24. SecureCRT python script to update hostname and banner This script is to update hostname and banner of cisco swtiches especially IOS. ****** # $language = "python" # $interface = "1.0" # # Author: Ethan Park # Date: 3/2/2020 # This script reads a csv file which contains hostname, IP address and a model # It updates hostname and banner section import csv import math def updateBanner(host, model): hostLength = int(math.ceil((35 - len(host)) / 2)) mode.. 2020. 3. 4. 이전 1 ··· 40 41 42 43 44 45 46 ··· 54 다음 반응형