일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- judge
- PostgreSQL
- numpy
- KAKAO
- CUDA
- docker
- pytorch
- file
- Package
- pandas
- format
- Container
- Database
- AI
- Python
- git
- Converting
- Flask
- Linux
- Paper
- DB
- Mac
- Windows
- evaluation
- enV
- TORCH
- list
- LLM
- Laravel
- GitLab
Archives
- Today
- Total
Daily Develope
[Python] Pickle library (object serialization) 본문
Pickle이란?
Python의 객체(Object)를 binary 파일로 serializing 하거나 반대로 binray 파일로부터 de-serializing 하기 위한 프로토콜이 구현된 라이브러리.
흔히 pickling, flattening, marshalling 등으로 일컫는다.
장점?
- Python 객체를 바로 파일로 쓰거나 읽을 수 있다.
- Binary(또는 Bytes) 형태로 데이터를 다루기 때문에 읽기/쓰기 속도가 빠르다.
읽기/쓰기 예시코드
import pickle
import os
my_filepath = "target/file/path/filename.bin"
my_data = ['target', 'data']
if os.path.isfile(my_filepath):
### 읽기
with open('pickle_data_path', 'rb') as f:
my_data = pickle.load(f)
else:
### 쓰기
with open('pickle_data_path', 'wb') as f:
pickle.dump(my_data, f)
참고
'Develope > Python' 카테고리의 다른 글
[Python] 반올림 (0) | 2024.08.20 |
---|---|
[Python] 엑셀 파일 다루기 with Pandas (0) | 2024.01.22 |
[Python] Postgresql 연동 / 연결 코드 샘플 (0) | 2023.10.03 |
[Python] 클래스 속성의 getter & setter 정의 (0) | 2023.09.11 |
[Python] 알면 도움되는 자주쓰는 문법 (tips) (0) | 2023.04.10 |
Comments