python

· Mac
iMessage 구조 Macbook에 iphone iMessage를 동기화하면 ~/Users/Name/Library/Messages 폴더에 저장된다. 저장된 폴더를 보면 .db로 관리되는 것을 볼수있다. sqlite로 저장되며 다양한 컬럼들이 있다.   주요 테이블은 message로 text와 attributedBody에서 메세지 본문을 찾을 수 있다. 더보기- **ROWID**: 각 행(row)의 고유 식별자.- **guid**: 메시지의 전역 고유 식별자.- **text**: 메시지의 내용.- **replace**: 대체 텍스트.- **service_center**: 메시지를 처리한 서비스 센터.- **handle_id**: 메시지의 송신자 또는 수신자의 ID.- **subject**: 메시지의 주제..
· 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
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
Python Command Flag python -c - (command) 직접 명령어를 입력해 Python 코드를 실행 ex) python -c "import pandas as pd" python -m - (module) Python 모듈을 스크립트로 실행. ex) 'python -m http.server' 현재 디렉토리에서 HTTP 서버 실행 python -i - (interactive) 스크립트 실행 후 대화형 모드로 진입 ex) 스크립트 실행 후 interpreter로 진입 python -O - (Optimize) 최적화 모드를 활성화, assert문을 제거하고 `__debug__`를 'False'로 설정 python -B - (bytecode) .pyc 파일을 생성하는 것을 방지. 보통 개발 중..
· Python
1 ) kwargs Python 3.12 부터 변수 Type에 관한 모듈이 많이 개선되었다. 그 중 Typing에 NotRequired, TypedDict, Unpack을 사용해서 class 정의와 함수 변수 관리가 좀더 용이해졌다. from typing import NotRequired, TypedDict, Unpack class Kwargs(TypedDict): name : str age : NotRequired[int] def profile(**kwargs: Unpack[Kwargs]) -> None: for k, v in kwargs.items(): print(f"{k}: {v}") if __name__ == "__main__": profile(name="Ethan", age=25) Kwargs의..
다했다
'python' 태그의 글 목록