使用 with 语句写入文件
This commit is contained in:
parent
ff5bc31174
commit
8800a0f19b
|
@ -2,6 +2,7 @@
|
||||||
# Author - HoneyMoose (https://www.ossez.com)
|
# Author - HoneyMoose (https://www.ossez.com)
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import ruamel.yaml as yaml
|
import ruamel.yaml as yaml
|
||||||
|
|
||||||
json_filename = 'resources/black_rock_test.json'
|
json_filename = 'resources/black_rock_test.json'
|
||||||
|
@ -18,6 +19,5 @@ with open(json_filename) as json_file:
|
||||||
json_file.close()
|
json_file.close()
|
||||||
|
|
||||||
# Write to YAML
|
# Write to YAML
|
||||||
yaml_file = open(yaml_filename, 'w+')
|
with open(yaml_filename, 'w') as yaml_file:
|
||||||
yaml.dump(data, yaml_file, allow_unicode=True)
|
yaml.dump(data, yaml_file, allow_unicode=True)
|
||||||
yaml_file.close()
|
|
||||||
|
|
Loading…
Reference in New Issue