Python

· Python
"..." @abstractmethod     def title(self) -> str: ...    Python에서 ...은 여러 가지 상황에서 쓰이는 특별한 객체다. 주요 용도는 다음과 같다.Ellipsis 객체 Python의 Ellipsis 객체는 ...로도 표현된다. 이 객체는 고급 슬라이싱(slicing) 및 다차원 배열과 같은 경우에서 주로 사용된다. 예를 들어, NumPy와 같은 라이브러리에서 다차원 배열의 특정 부분을 슬라이스할 때 유용하다.import numpy as nparr = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])print(arr[..., 1]) # 다차원 배열의 모든 차원에서 1번째 인덱스를 선택  함수 및 ..
· Python
File "/home/U/anaconda3/lib/python3.8/site-packages/OpenSSL/crypto.py", line 1537, in X509StoreFlags    CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECKAttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'  원인1) 현재 사용 중인 환경의 python library가 낮은 버전을 사용 ubuntu 기타 os에서 default로 python은 2.x python3는 3.x 버전을 사용하는데 이때 가상환경을 사용하면서 PATH가 잘 잡혀져 있지 않으면 환경은 낮은 버전 사용하는 스크립트는 높은 버전을 사용..
· Python
Python String Methods1) capitalize() : 문자열의 첫 글자를 대문자로 변환text: str = "hello"print(text.capitalize()) # Hello2) casefold() : 문자열을 소문자로 변환text1: str = 'MARIo'text2: str = 'maRIO'print(text1.casefold()) # marioprint(text2.casefold()) # marioprint(text1.casefold() == text2.casefold()) # True3) center() : 문자열을 가운데 정렬text: str = "hello"print(text.center(20)) # hello print(text.center(20,..
· Python
“Formatted String Literals.” 1) f-string nested in nested python 버전이 올라가면서 다양하고 편리한 기능이 많이 생겼다. 그 중하나인 f-string 안에 다시 f-string을 사용하는 것이다. 이렇게 되면 앞서 소개한 f-string trick(1)의 datetime을 자유자재로 사용할 수 있다. from datetime import datetime now : datetime = datetime.now() date_spec : str = "%d.%m.%Y" date = now | date_spec print(f"{now:{date_spec}}") # '17.03.2024' 2) file path file path를 문자열로 처리할 때 escape ..
· Python
Python 처음 접하는 사람들이 하는 흔한 실수 1) try ~ except~ 구문 구문 사용할 때 error문을 직접 그것도 이상하게 작성하는 경우가 많다. python에서 사용하는 error 구문을 사용하면 될 일을 나만이 알아보게 해놓는것이 큰 실수로 이어진다. [Worse] total: float = 0 while True: user_input: str = input("Add: ") try: total += float(user_input) except: print('숫자만 입력해주시오.') print(f"Current: {total}") [Better] total: float = 0 while True: user_input: str = input("Add: ") try: total += floa..
· Python
Python f-string을 활용한 깔끔한 출력 1) int 문자열 출력 f-string으로 숫자를 가독성이 좋은 형태로 구분자 선택을 할 수 있다. n : int = 1000000 print(f"{n}") # 1000000 print(f"{n:_}") # 1_000_000 print(f"{n:,}") # 1,000,000 2) 문자열 출력 blank space 채우기 특정 항목을 출력할 때 문자열의 길이가 달라 보기힘든 경우 일일히 문자열의 크기만큼 빈칸을 사용해야한다. 이 경우 f-string으로 보정할 수있다. type1 : str = 'color' type2 : str = 'size' print(f"{type1:
· Python
JinjaTemplates에서 사용하는 {{url_for()}}의 parameter가 fastAPI 모듈 Jinja2Templates 모듈 parameter와 달라서 발생 filename -> path line 707, in url_path_for raise NoMatchFound(name, path_params) starlette.routing.NoMatchFound: No route exists for name "/static" and params "path". # AS-IS # TO-BE
· Python
https://github.com/pypa/pip/issues/11436 Only emit a metadata warning once · Issue #11436 · pypa/pip From #11352 (comment) BTW, the warning is quite noisy: [root@9a62f3789682 /]# mkdir -p /usr/lib64/python3.11/site-packages/mercurial-6.2-py3.11.egg-info [root@9a62f3789682 /]# pip list WARNING: Ski... github.com 원인 mac에서 homebrew로 package 설치시 metadata 소실로 warning 발생 WARNING: Skipping /opt/homebre..
다했다
'Python' 카테고리의 글 목록