使用 with 语句写入 yaml 文件
This commit is contained in:
parent
8800a0f19b
commit
b0ee521470
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue