From b0ee52147006b662233d37dc4e5d07e91ddb3e81 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Thu, 11 Mar 2021 10:51:43 -0500 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20with=20=E8=AF=AD=E5=8F=A5?= =?UTF-8?q?=E5=86=99=E5=85=A5=20yaml=20=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/FileWith.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/FileWith.py b/tests/FileWith.py index b989bb5..221189c 100644 --- a/tests/FileWith.py +++ b/tests/FileWith.py @@ -3,7 +3,10 @@ import json +import ruamel.yaml as yaml + json_filename = 'resources/honeymoose_test.json' +yaml_filename = 'resources/honeymoose_test.yaml' # Read and process JSON with open(json_filename) as json_file: @@ -15,3 +18,7 @@ with open(json_filename) as json_file: print(str(label_id)) print(json_file.closed) + +# Using with write to YAML +with open(yaml_filename, 'w') as yaml_file: + yaml.dump(data, yaml_file, allow_unicode=True)