some useful shortcuts for pyyaml
Project description
gmanka yml
some useful shortcuts for pyyaml
installation
pip install gmanka_yml
functions
to_str^
converts any data to yml string and returns it
import gmanka_yml as yml
my_dict = {
'element_1': 1,
2: 'element_2',
3: [
'list_element_1',
'list_element_2',
]
}
print(yml.to_str(my_dict))
output:
element_1: 1
2: element_2
3:
- list_element_1
- list_element_2
to_file^
same as to_str, but writes data to file instead of returning
yml.to_file(
data = my_dict,
path = 'file.yml',
)
from_str^
import gmanka_yml as yml
my_str = '''
element_1: 1
2: element_2
3:
- list_element_1
- list_element_2
'''
my_dict = yml.from_str(my_str)
print(my_dict)
print(type(my_dict))
output:
{'element_1': 1, 2: 'element_2', 3: ['list_element_1', 'list_element_2']}
<class 'dict'>
from_file^
same as from_str, but reads data from file
yml.from_file('file.yml')
default values
yml.from_str(1) # raises TypeError
yml.from_str(1, default = None) # returns None
expected_type
yml.from_str(
data = '{}',
expected_type = list,
) # raises TypeError
yml.from_str(
data = '{}',
default = None,
expected_type = list,
) # returns None
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gmanka_yml-23.0.4.tar.gz
(1.9 kB
view hashes)
Built Distribution
Close
Hashes for gmanka_yml-23.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c08f6c3de76a40b4fc6fcfdaf476518adc3de9882931db0099cfc0406fc1891 |
|
MD5 | e16dfade93c80b952c4a10aa70058508 |
|
BLAKE2b-256 | 979acc1c53943481c93e82fe7de4a7752a5d5dc8ec1b2ea92ad1d0b192aff67f |