Created
March 28, 2022 17:14
-
-
Save agiletalk/bf3e0d02cc2fe02ba5ff69df54846762 to your computer and use it in GitHub Desktop.
[실용주의 프로그래머] 연습 문제 11: .yaml 파일을 .json 파일로 바꾸기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import yaml | |
import json | |
def get_file_list_yaml(path): | |
return [file for file in os.listdir(path) if file.endswith(".yaml")] | |
def yaml_to_json(yaml_file, json_file): | |
with open(yaml_file, 'r') as yaml_in, open(json_file, 'w') as json_out: | |
yaml_object = yaml.safe_load(yaml_in) | |
json.dump(yaml_object, json_out) | |
if __name__ == '__main__': | |
file_list_yaml = get_file_list_yaml(sys.argv[1]) | |
for file in file_list_yaml: | |
file_name, ext = os.path.splitext(file) | |
yaml_to_json(file, file_name+".json") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment