Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- windows forms
- 컨테이너
- LIST
- C
- pip
- pytorch
- 오류
- error
- Linux
- Visual Studio
- Selenium
- 프로그래머스
- VS Code
- paramiko
- 기타 연주
- C#
- Numpy
- Docker
- Python
- OpenCV
- label
- YOLO
- C++
- 핑거스타일
- ubuntu
- mysql
- pandas
- 채보
- SSH
- JSON
Archives
- Today
- Total
기계는 거짓말하지 않는다
Python 객체 파일로 저장, 직렬화 (pickle) 본문
Python 객체를 파일로 저장할 때 기본 내장된 pickle 모듈을 사용할 수 있다.
pickle — Python object serialization
Source code: Lib/pickle.py The pickle module implements binary protocols for serializing and de-serializing a Python object structure. “Pickling” is the process whereby a Python object hierarchy is...
docs.python.org
간단한 사용법은 아래와 같다.
import pickle
class TempClass(object):
def __init__(self, string: str, val: int):
self.string = string
self.val = val
with open('temp_data.pkl', 'wb') as wf: # pickle.HIGHEST_PROTOCOL 대용량 메모리 인수
temp1 = TempClass('temp1', 100)
pickle.dump(temp1, wf, pickle.HIGHEST_PROTOCOL)
temp2 = TempClass('temp2', 200)
pickle.dump(temp2, wf, pickle.HIGHEST_PROTOCOL)
with open('temp_data.pkl', 'rb') as rf:
temp1 = pickle.load(rf)
print(temp1.string)
print(temp1.val)
temp2 = pickle.load(rf)
print(temp2.string)
print(temp2.val)
'Python' 카테고리의 다른 글
Python SSH Client 원격 연결 (Paramiko) (0) | 2023.02.24 |
---|---|
Python 깊은 복사, 얕은 복사 (Shallow Copy, Deep Copy) (0) | 2023.02.12 |
Python 변수 타입 선언 (0) | 2023.01.28 |
Python Pandas 다수 열의 조건 값 추출 (0) | 2023.01.21 |
Python Pandas 특정 열의 특정 값, 특정 열의 다수 값 추출 (0) | 2023.01.21 |
Comments