Custom Query (121 matches)
Results (46 - 48 of 121)
| Ticket | Resolution | Summary | Owner | Reporter |
|---|---|---|---|---|
| #40 | worksforme | incomplete dict constructor | xi | dvd@… |
| Description |
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@… |
| Description |
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? |
|||
| #11 | fixed | Unicode support | xi | edemaine@… |
| Description |
I would like to bring up two issues with Unicode support in PyYAML's emitter. First, it emits a type annotation of !!python/unicode whenever emitting a unicode string that can be encoded in ASCII: >>> print yaml.dump(u'Fran\xe7ais') "Fran\xE7ais" >>> print yaml.dump(u'hello') !!python/unicode 'hello' I assume this is to force the value to be a unicode string when read back in. However, it makes for rather ugly files. In my case, and I imagine many others, I really don't care whether a string is stored as a 'str' or as a 'unicode' object in Python. And in YAML, the native string type is Unicode anyway. So it seems strange to have this distinction at the level of the YAML file. On the other hand, I understand the desire to have yaml.load(yaml.dump(x)) == x. Perhaps this should be another configuration option? (Of course, I could just convert my ASCII-encodable unicode objects to str objects...) The second issue is that the emitter escapes non-ASCII characters even when all characters are printable (according to 'c-printable' in the YAML spec) when using an encoding (UTF8) that supports such characters. I don't find this as elegant as could be. Instead of the "Fran\xE7ais" output above, I would have hoped for the UTF8-encoded byte string Fran\xc3\xa7ais\n. I guess this is as stylistic an issue as the previous one. It makes me wonder again whether there should be a Style object that can specify various emitting options, instead of many keyword arguments... |
|||
