Python
-
Python - Coroutine (Python 2.2)Python 2020. 11. 7. 11:07
Python 2.2 Python 2.2 에서는 lightweight coroutine 지원이 추가되었고 이를 generator라고 부른다(PEP 255 – Simple Generator). 유사한 두 함수 선언 def fun1(): print('print 1') print('print 2') def gen1(): print('yield 1') yield 10 print('yield 2') yield 20 실행의 차이 >>> fun1() print 1 print 2 >>> gen1() 내부적 구분 type값 비교. 'generator'라는 차이가 보인다. >>> type(fun1()) print 1 print 2 >>> type(fun1) >>> >>> type(gen1()) >>> type(gen1) >..
-
Python - TkInter gui 기초Python 2020. 9. 9. 18:01
Tk interface, Tk GUI toolkit. tkinter are available on most Unix platforms, as well as on Windows systems. >>> >>> import tkinter >>> tk = tkinter.Tk() >>> btn = tkinter.Button(tk, text="kkk") >>> btn.pack() >>> #tk.mainloop() # Our script will remain in the event loop until we close the window import tkinter as tk wd = tk.Tk() lb = tk.Label(wd, text="Hello Tk!") lb.pack() wd.mainloop() timer ex..
-
Python - OpenCVPython 2020. 9. 9. 14:37
OpenCV OpenCV (Open Source Computer Vision Library) 초기 Intel에서 개발 시작. 다양한 Os에서 작동되고 있다. IoT장비나 RaspberryPi 등의 싱글보드에서도 사용할 수 있다. 설치 "pip install opencv-python" version 4.4의 경우 33.5MB나 된다. 간단한 png 보여주기 Ex >>> >>> import cv2 >>> img = cv2.imread("t.png") >>> cv2.imshow("Name1", img) >>> cv2.waitKey(0) 13 >>> cv2.destroyWindow("Name1") >>> matplotlib에 적용 Ex >>> >>> import matplotlib >>> matplotlib.p..
-
Python - itertoolsPython 2020. 9. 8. 13:01
2020/09/06 - Python - product 2020/09/06 - Python - combination 클래스 함수 2020/09/06 - Python - permutations 클래스 함수 product('ABCD', 2) AA AB AC AD BA BB BC BD CA CB CC CD DA DB DC DD for2(a=0,...) for2(b=0,...) [a][b] permutations('ABCD', 2) AB AC AD BA BC BD CA CB CD DA DB DC (A~D 4점에 쌍방향 연결 효과) for2(a=0,...) for2(b=0,...) if(a!=b) [a][b] combinations('ABCD', 2) AB AC AD BC BD CD (A~D 4점에 단방향 연결 효..
-
Python - namedtuplePython 2020. 9. 8. 01:31
>>> from collections import namedtuple >>> >>> C1 >>> c1 = C1('aa', 'bb', 'cc') >>> c1 C1(mA='aa', mB='bb', mC='cc') >>> c1.mB 'bb' >>> >>> C1([11,22,33]) TypeError: __new__() missing 2 required positional arguments: 'mB' and 'mC' >>> C1(*[11,22,33]) C1(mA=11, mB=22, mC=33) >>> C1._make([11,22,33]) C1(mA=11, mB=22, mC=33) >>> 응용 Db, Csv Employee = namedtuple('Employee', 'name, age') import csv f..