[...] ํŒŒ์ด์ฌ ์–ด๋””๊นŒ์ง€ ์•„๋‹ˆ?
ยท
๐Ÿ 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๋ฒˆ์งธ ์ธ๋ฑ์Šค๋ฅผ ์„ ํƒ  ํ•จ์ˆ˜ ๋ฐ ..
[site-packages] AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'
ยท
๐Ÿ 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๊ฐ€ ์ž˜ ์žกํ˜€์ ธ ์žˆ์ง€ ์•Š์œผ๋ฉด ํ™˜๊ฒฝ์€ ๋‚ฎ์€ ๋ฒ„์ „ ์‚ฌ์šฉํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋Š” ๋†’์€ ๋ฒ„์ „์„ ์‚ฌ์šฉ..
string method. 1~20
ยท
๐Ÿ 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] f-string trick (2)
ยท
๐Ÿ 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
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] f-string trick (1)
ยท
๐Ÿ 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:
FastAPI - starlette.routing.NoMatchFound: No route exists for name
ยท
๐Ÿ 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
[pip] WARNING: Skipping due to invalid metadata entry 'name'
ยท
๐Ÿ 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' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก