Python345 Python _ zoneinfo 사용법, ZoneInfo 와 pytz 차이 ZoneInfo 을 사용하면 기존 pytz를 사용하지 않고도 타임존을 사용할 수 있다! (*ZoneInfo 는 Python3.9 버전 이상부터 사용가능) 'ZoneInfo' vs 'pytz' 그렇다면 ZoneInfo 와 pytz 는 어떤 차이가 있을까? 우선 ZoneInfo 는 따로 설치할 필요가 없는 빌트인 클래스이므로 다음처럼 간단하게 불러올 수 있다. from zoneinfo import ZoneInfo ZoneInfo 와 pytz 를 각각 사용해 현재시간을 가져와보자. pytztz = timezone("Asia/Seoul") zonetz = ZoneInfo("Asia/Seoul") print(datetime.datetime.now(tz=pytztz).tzname()) print(datetime.d.. 2022. 10. 27. FastAPI _ BaseSettings 을 lru_cache 할 때, unhashable type 에러 해결방법 BaseSettings을 사용한 객체를 lru_cache 할 때, TypeError: unhashable type: 에러가 발생할 때가 있다. 정리하면 다음과 같은 상황이다. given FastAPI 에서 lru_cache로 반환하는 BaseSettings 객체를, when 다시 lru_cache를 사용하는 함수가 인수로 받을 때, then TypeError: unhashable type: 에러가 발생함. e.g class Config(BaseSettings): URL: str = Field(..., env="URL") class Config: env_file = "secrets/.env" env_file_encoding = "utf-8" @lru_cache def get_config() -> Confi.. 2022. 10. 26. pytest _ 비동기 테스트 실행하기 (feat. auto 모드) pytest 에서 async 테스트 함수를 실행하는 방법에는 'strict 모드' 와 'auto 모드' 가 있다. 오늘은 손쉽게 비동기 테스트를 할 수 있는 'auto 모드' 에 대해 알아보자. 먼저 pytest-asyncio 를 설치한다. pip install pytest-asyncio 아래 1번과 2번 중에 하나를 선택하여 파일과 코드를 추가한다. 1번 # pytest.ini [pytest] asyncio_mode = auto 2번 # pyproject.toml [tool.pytest.ini_options] asyncio_mode = "auto" 이것으로 'auto 모드' 설정이 끝났다. auto 모드는 pytest.ini 혹은 pyproject.toml 파일에 옵션 코드를 추가하여 async 테스트.. 2022. 10. 26. 1026. Beginner Series #4 Cockroach The cockroach is one of the fastest insects. Write a function which takes its speed in km per hour and returns it in cm per second, rounded down to the integer (= floored). For example: 1.08 --> 30 Note! The input is a Real number (actual type is language dependent) and is >= 0. The result should be an Integer. Solution: def cockroach_speed(s): import math return math.floor(km_to_cm(s) / hour_to.. 2022. 10. 26. 1024. Sum The Strings Create a function that takes 2 integers in form of a string as an input, and outputs the sum (also as a string): Example: (Input1, Input2 -->Output) "4", "5" --> "9" "34", "5" --> "39" "", "" --> "0" "2", "" --> "2" "-5", "3" --> "-2" Notes: If either input is an empty string, consider it as zero. Inputs and the expected output will never exceed the signed 32-bit integer limit (2^31 - 1) Solutio.. 2022. 10. 24. 1023. No Loops 2 - You only need one No Loops Allowed You will be given an array a and a value x. All you need to do is check whether the provided array contains the value, without using a loop. Array can contain numbers or strings. x can be either. Return true if the array contains the value, false if not. With strings you will need to account for case. Looking for more, loop-restrained fun? Check out the other kata in the series:.. 2022. 10. 23. 이전 1 ··· 14 15 16 17 18 19 20 ··· 58 다음