Skip to content

Instantly share code, notes, and snippets.

@Wegazz
Created November 9, 2019 08:16
Show Gist options
  • Save Wegazz/e5826c8ba6e6bc068e8886cee95668b0 to your computer and use it in GitHub Desktop.
Save Wegazz/e5826c8ba6e6bc068e8886cee95668b0 to your computer and use it in GitHub Desktop.
Работа с YAML файлами настрек
# -*- coding: utf-8 -*-
import yaml
import io
configFile = 'test_yaml.yaml'
# Define data
data = {
'a list': [
1,
42,
3.141,
1337,
'help',
u'€'
],
'a string': 'bla',
'another dict': {
'foo': 'bar',
'key': 'value',
'the answer': 42
}
}
# Write YAML file
with io.open(configFile, 'w', encoding='utf8') as outfile:
yaml.dump(data, outfile, default_flow_style=False, allow_unicode=True)
# Read YAML file
with open(configFile, 'r', encoding='utf8') as stream:
data_loaded = yaml.safe_load(stream)
print("Данные идентичны" if data == data_loaded else "Данные разнятся")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment