Programming(72)
-
[Python] Lambda expression (람다 표현식)
lambda param : body >>> add_10 = lambda x : x + 10 >>> >>> add_10(1) 11 >>> (lambda arg : arg + 10)(1) 11 >>> (lambda : 1)() 1 Python lambda expression 내에서는 변수 선인이 불가능 >>> y = 10 >>> (lambda arg : arg + y)(1) 11 >>> def plus(x): ... return x + 10 >>> list(map(plus, [1])) [11] >>> >>> list(map(plus, [1, 2])) [11, 12] >>> list(map(lambda arg : arg + 10, [1, 2])) [11, 12] map, filter, reduce 함수 사용 ..
2021.12.13 -
Python access member as string
You from time to time meet a case that you need to set member varialbe. In such a case, if you get a class with lots of member varialbe, then code to set/get is somewhat burden. In such case, there are very simple way to do. I'll let you know in this article. class definition Assume that there is a class with three member attributes as follow. class Item: def __init__(self): self.key = None ..
2021.12.10 -
Python access member with string
Python class의 맴버에 값을 설정해야 할 때가 있다. 그런데, member가 너무 많은 경우 일일이 값들을 set, get 하는 코드를 작성하기 힘들 수 있습니다. 이런 경우 매우 손쉽게 string 배열을 통해 값을 설정하는 법을 알려드리겠습니다. class 정의 아래와 같이 3개의 member attribute를 지니고 있는 class가 있다고 합시다. class Item: def __init__(self): self.key = None self.cat = None self.file = None 일반적인 값 설정 방법 위 class에 값을 설정하는 일반적인 방법은 다음과 같습니다. item = Item() item.key = 1 item.cat = 3 item.file = 'filen..
2021.12.10 -
openpyxl sheet
openpyxl import 가장 먼저 openpyxl을 import 해야 합니다. import openpyxl from openpyxl.styles.borders import Border, Sidedeclare workbook 작업할 Workbook instance를 선언합니다. wb = openpyxl.Workbook()create a new sheet workbook 내에 sheet을 생성합니다. wb.create_sheet('sheet 1', 0)sheet에 cell들을 추가하기 위해서 객체를 얻어옵니다. sheet = wb.get_sheet_by_name('sheet 1')adding cells use Border for each cell 각 cell에 적용할 bor..
2021.12.10 -
openpyxl sheet
openpyxl import The first thing you need to do is import openpyxl as follow. import openpyxl from openpyxl.styles.borders import Border, Sidedeclare workbook declare a new instance of Workbook wb = openpyxl.Workbook()create a new sheet create the first sheet in the workbook. wb.create_sheet('sheet 1', 0)and get the reference to the sheet sheet = wb.get_sheet_by_name('sheet 1')add..
2021.12.10 -
Go empty interface
(cont.) emptyp interface 모든 type을 "표현"하는 interface 즉, dynamic type이며 이는 Java의 Object, C의 void*와 유사하다. func show(v interface{}) { fmt.Println(v) } var x interface{} x = 1 x = "A" show(x) // "A" func main() { var a interface{} = 1 i := a j := a.(int) // j는 int type, 값은 1 println(i) // pointer address println(j) // 1 }
2021.12.09