Questions tagged [pyyaml]

PyYAML is a YAML 1.1 parser and emitter for Python. Use this tag for PyYAML specific python questions.

PyYAML is a parser/dumper for YAML 1.1 for the Python programming language.

PyYAML does not yet implemented the feature changes from the YAML 1.2 specification released in 2009.

See http://pyyaml.org/wiki/PyYAML for background and documentation.

Source code: https://github.com/yaml/pyyaml

828 questions
15
votes
4 answers

python yaml.dump format list in other YAML format

I want to dump a Python object to a YAML file like this: a: 5 b: 6 c: 7 d: [ 1,2,3,4] but NOT a: 5 b: 6 c: 7 d - 1 - 2 - 3 - 4 image d was a massive list, the output gets messy for humans to see. I use: default_flow_style=False but this uses the…
Gordon
  • 393
  • 1
  • 3
  • 8
15
votes
1 answer

Disable PyYAML value conversion

I have just started to use PyYAML to convert some data. I just use the yaml.load function and it was good enough for me until I noticed that it tries to convert all values to uni-coded string, int, dates and so on. This could be fatal in my…
theAlse
  • 5,577
  • 11
  • 68
  • 110
15
votes
1 answer

forcing pyYAML to dump consistently

In [136]: a = [1,2,3,4,5] In [137]: print yaml.dump(a) [1, 2, 3, 4, 5] In [138]: a = [1,2,3,4,5, [1,2,3]] In [139]: print yaml.dump(a) - 1 - 2 - 3 - 4 - 5 - [1, 2, 3] why are the outputs of above two dumps different? Is it possible to force…
Anuvrat Parashar
  • 2,960
  • 5
  • 28
  • 55
14
votes
3 answers

Why are some Python package names different than their import name?

Some packages are imported with a string which is different from the name of the package on PyPI, e.g.: $ pip list | grep -i "yaml\|qt" PyYAML 3.13 QtPy 1.5.2 pyyaml (pip instal pyyaml), but import yaml qtpy (pip…
emcek
  • 459
  • 1
  • 6
  • 17
14
votes
3 answers

How to append data to YAML file

I have a file *.yaml with contents as below: bugs_tree: bug_1: html_arch: filepath moved_by: user1 moved_date: '2018-01-30' sfx_id: '1' I want to add a new child element to this file under the node [bugs_tree] I have tried to do…
Qex
  • 317
  • 1
  • 3
  • 9
14
votes
1 answer

PyYAML and unusual tags

I am working on a project that uses the Unity3D game engine. For some of the pipeline requirements, it is best to be able to update some files from external tools using Python. Unity's meta and anim files are in YAML so I thought this would be…
renderbox
  • 1,595
  • 14
  • 25
14
votes
3 answers

pyYAML Errors on "!" in a string

First, a disclaimer: I'm not too familiar with YAML. I'm trying to parse a YAML doc into Key Value Pairs (don't worry about how I'm doing it. I've got that bit handled) My file used to look something like: world: people: name:Suzy …
Rokujolady
  • 939
  • 2
  • 8
  • 15
13
votes
3 answers

Default constructor parameters in pyyaml

I haven't been able to find out how to do this in the PyYAML documentation. I want to represent python classes I've defined in YAML, and have a default value given to a parameter in the constructor if it's not specified in the YAML. For example: >>>…
Colin
  • 10,447
  • 11
  • 46
  • 54
13
votes
1 answer

pyyaml load number as decimal

yaml.load loads numbers as Python floats. I cannot find a straightforward way to override this. Compare json.load, which allows parse_float=Decimal if you want to parse floating point numbers as decimal.Decimals. Is there any way to accomplish this…
jsharp
  • 565
  • 2
  • 14
13
votes
4 answers

Creating Custom Tag in PyYAML

I'm trying to use Python's PyYAML to create a custom tag that will allow me to retrieve environment variables with my YAML. import os import yaml class EnvTag(yaml.YAMLObject): yaml_tag = u'!Env' def __init__(self, env_var): …
doremi
  • 14,921
  • 30
  • 93
  • 148
13
votes
9 answers

Cygwin - How to install ansible?

How to get / install ansible using Cygwin? I tried the following steps but it's didn't work during bullet 5 (while running "python setup.py install"). Steps taken from: Taken from https://servercheck.in/blog/running-ansible-within-windows 1)…
AKS
  • 16,482
  • 43
  • 166
  • 258
13
votes
1 answer

Specifying styles for portions of a PyYAML dump

I'm using YAML for a computer and human-editable and readable input format for a simulator. For human readability, some parts of the input are mostly amenable to block style, while flow style suits others better. The default for PyYAML is to use…
cge
  • 9,552
  • 3
  • 32
  • 51
12
votes
2 answers

Loading document as raw string in yaml with PyYAML

I want to parse yaml documents like the following meta-info-1: val1 meta-info-2: val2 --- Plain text/markdown content! jhaha If I load_all this with PyYAML, I get the following >>> list(yaml.load_all(open('index.yml'))) [{'meta-info-1': 'val1',…
sharat87
  • 7,330
  • 12
  • 55
  • 80
12
votes
1 answer

Why does PyYAML use generators to construct objects?

I've been reading the PyYAML source code to try to understand how to define a proper constructor function that I can add with add_constructor. I have a pretty good understanding of how that code works now, but I still don't understand why the…
Ryan
  • 123
  • 7
12
votes
4 answers

Can I dump blank instead of null in yaml/pyyaml?

Using PyYAML, if I read in a file with blank values in a dict: test_str = ''' attrs: first: second: value2 ''' This returns None for the key first: >>> data = yaml.load(test_str) >>> data {'attrs': {'second': 'value2', 'first': None}} But when…
Michael Delgado
  • 13,789
  • 3
  • 29
  • 54