본문 바로가기

언어 정리/python_lib,일급함수18

json_to_X, X_to_json 인코딩 디코딩 방식은 다른 방식도 많음 참고만하세요 json.dumps 에서는 ' 와 \ 를 제외한 특수기호에 에러를 일으키지 않는다 ' 이거는 json 을 감싸주는 역할이므로 \ 원화표시는 특수기호를 지칭하는 특특수기호~ 이라서 딕셔너리 리스트,딕셔너리 딕셔너리 바이트 ( 바로 변환불가 str로 변환후 json 해줘야함 ) 여기서 볼부분은 \ 표시임. json 에서는 ' ' 안에 " " 를 넣어서 표현하는데(' " " ') 이런 경우는 " " 안에 ' ' 이 들어가야 하는 상황이다.(' " ' ' , ' ' " ') 따라서 " " 안에 들어가는 ' ' 에게는 \표시를 넣어서 표현한다. (' " ' ' , ' ' " ') -> (' " \' \' , \' \' " ') 바이트 어레이(리스트) 원래 그냥 .. 2022. 10. 25.
unittest tutorial 개념 정리 참고 : https://docs.python.org/3/library/unittest.html unittest — Unit testing framework — Python 3.10.7 documentation unittest — Unit testing framework Source code: Lib/unittest/__init__.py (If you are already familiar with the basic concepts of testing, you might want to skip to the list of assert methods.) The unittest unit testing framework was originally inspired by docs.python.org https://ac.. 2022. 9. 19.
with 함수 ( __enter__, __exit__ ) 자원을 사용 할떈 1. 자원 획득 2. 자원 사용 3. 자원 반납 구조가 필요함. 1. __enter__ 일급함수 2. 자원 사용할 일반함수 3. __exit__ 일급함수 with 를 쓰면 일일히 자원 획득부터 반납까지(1 ~ 3) 단계를 쓸 필요가 없다. 자동으로 획득후 사용 , 사용다하고 스코프를 나가면 반납 함. 형식 : with 클래스명( ) as 네임: 네임.자원함수() 예시 : class Hello: def __enter__(self): # 사용할 자원을 가져오거나 만든다(핸들러 등) print('enter...') return self # 반환값이 있어야 VARIABLE를 블록내에서 사용할 수 있다 def sayHello(self, name): # 자원을 사용한다. ex) 인사한다 print.. 2022. 9. 19.
import contextvars 설명 https://www.geeksforgeeks.org/context-variables-in-python/ Context Variables in Python - GeeksforGeeks A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. www.geeksforgeeks.org 요즘 파이썬에서 parameter 로 contextvars 가 자주 나오길래 정리해봄 # import modu.. 2022. 8. 28.
functools.partial() 정리 https://wikidocs.net/109304 031 기존 함수로 새로운 함수를 만들려면? ― functools.partial functools.partial()은 하나 이상의 인수가 이미 채워진 새 버전의 함수를 만들 때 사용하는 함수이다. ## 문제 다음은 입력한 인수의 합과 곱을 choic ... wikidocs.net 한 함수에 parameter 를 고정하고 재정의해서 쓰는 lib 전부 고정할 수 도 있고, 하나만 고정 할 수도 있다. 예시_1 : def add_mul(choice, *args): if choice == "add": result = 0 for i in args: result = result + i elif choice == "mul": result = 1 for i in arg.. 2022. 8. 17.
PIL , 출력문 저장 lib(write,print,sys.out) 참조 개념이나 모드 설명 https://pillow.readthedocs.io/en/stable/handbook/concepts.html#concept-modes Concepts The Python Imaging Library handles raster images; that is, rectangles of pixel data. Bands: An image can consist of one or more bands of data. The Python Imaging Library allows you to store several... pillow.readthedocs.io 사용법 예시 https://pillow.readthedocs.io/en/stable/reference/Image.html Image M.. 2022. 8. 4.