Skip to content

Instantly share code, notes, and snippets.

@agiletalk
Created March 28, 2022 17:14
Show Gist options
  • Save agiletalk/bf3e0d02cc2fe02ba5ff69df54846762 to your computer and use it in GitHub Desktop.
Save agiletalk/bf3e0d02cc2fe02ba5ff69df54846762 to your computer and use it in GitHub Desktop.
[실용주의 프로그래머] 연습 문제 11: .yaml 파일을 .json 파일로 바꾸기
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