Custom Query (132 matches)


Show under each result:

Results (49 - 51 of 132)

Ticket Resolution Summary Owner Reporter
#59 worksforme Load yaml data as utf-8 strings into a dictionary xi dukebody@…

Reported by dukebody@…, 7 years ago.


Hello, I'm looking for support, but I don't know if this is the right place to ask.

I'm using PyYAML to load some nested data from an utf-8 encoded file in Python with:

import yaml

The data variable becomes a dictionary with unicode values where is needed. What I want is to put utf-8 strings instead of unicode values to use this data with another library: Cheetah. If I try to use the unicode-type dictionary generated by default with PyYAML I get an UnicodeDecodeError, because de Cheetah strings are in iso-8859-15 and Python tries to decode them to Unicode using ASCII charset tables, so it obiously fails.

Is there any way to get an utf-8 coded dictionary?

#40 worksforme incomplete dict constructor xi dvd@…

Reported by dvd@…, 7 years ago.


Hi all,

I'm puzzled by a strange behavior of yaml

If you run the attached script you obtain an output like this:

{'date': '732638',
'fields': {},
'guid': '0000010f153544cf8a314808007f000000000001',
'expiration': None}
{'date': '732638',
'fields': {'': {}, 'it': {'title': 'Hello World'}},
'guid': '0000010f153544cf8a314808007f000000000001',
'expiration': None}

*Please note the 'fields' value (I wrap the output to increase legibility)*

the first line is printed inside this custom constructor function:

def news_constructor(loader, node):
    nodes = loader.construct_mapping(node)
    print nodes
    return nodes

the second line (the correct one) is the print of the return values of this function

Can you help me or explain me this strange behavior?

#9 fixed Forcing block style xi edemaine@…

Reported by edemaine@…, 8 years ago.


Is there an easy way to force the emitter to use block style instead of flow style? I have one particular case in mind where it would be particularly desirable: ordered dictionaries. For example:

>>> yaml.load('[hello: world, goodbye: world]')
[{'hello': 'world'}, {'goodbye': 'world'}]
>>> print yaml.dump(_)
- {hello: world}
- {goodbye: world}

In my opinion, the output would look much nicer as

- hello: world
- goodbye: world

Even if you don't agree with this opinion, there should be a way to force block style in all output. I did not see an easy way to do this, even with subclassing. Suggestions?

Note: See TracQuery for help on using queries.