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 | 29 | 30 |
Tags
- cs224n
- json
- review
- text
- Stanford
- language_model
- gensim
- Ai
- linux
- paper_review
- machinelearning
- github
- pip
- computer_setting
- Standford
- computer
- tab
- nlp
- slideshare
- terminal
- cs231n
- code
- natural_language_processing
- Vim
- install
- seq2seq
- deeplearning
- Statistics
- error
- git
Archives
- Today
- Total
NLP/AI/Statistics
python json 파일 저장 및 불러오기 본문
dictionary를 저장하기 위해 json 파일을 생성하였다.
우선, json 저장 방법은 다음과 같다.
$ import json
$ with open('./file_name.json', 'w') as f:
$ json.dumps(dictionary, f)
# or
$ save_file = open('./file_name.json','w')
$ json.dump(dictionary, save_file)
$ save_file.close()
dictionary를 'file_name'이라는 파일명으로 저장하려고 할 때 위의 코드와 두 가지 방법으로 저장할 수 있다.
저장한 json 파일을 불러오기 위한 코드는 다음과 같다.
$ with open('./file_name.json', 'r') as f:
$ json_data = json.load(f)
$ json_data = json.dumps(json_data)
위와 같이 불러오면 json_data라는 변수명으로 dictionary가 불러와진다.
'Computer Setting > Python & ETC' 카테고리의 다른 글
python 지수 표현 변경 (0) | 2021.06.11 |
---|---|
python json 파일 한글 깨짐 현상 (0) | 2021.06.09 |
docker 비밀번호 변경 (0) | 2020.10.22 |
python default version 변경 (0) | 2020.10.22 |
Virtualenv 생성 (0) | 2020.10.22 |
Comments