Re: Counter intuitive default value for 'allow_unicode' in PyYAML
Kirill Simonov <[email protected]>
| Newsgroups | gmane.text.yaml.general |
|---|---|
| Message-ID | <[email protected]> |
Andrey Somov wrote:
> Hi,
>
> By default PyYAML outputs an ASCII character stream escaping Unicode
> characters:
>
> 'Über' -> '\xDCber'
Technically, it's "\xDCber", not '\xDCber'. The former is a
representation of the text:
Über
while the latter is a representation of the text:
\xDCber
Note:
>>> print yaml.load('Über')
Über
>>> print yaml.load(r''' "\xDCber" ''')
Über
>>> print yaml.load(r''' '\xDCber' ''')
\xDCber
PyYAML is completely in compliance with the YAML specs here. There are
two choices for the emitter when it encounters a non-ASCII character:
either emit the scalar in the UTF-8 encoding or use the double-quote
style and escape non-ASCII characters. Both are correct and supported
by the PyYAML emitter. By default, the emitter uses the conservative
approach: it escapes non-ASCII characters since it ensures that the
document is always readable on ASCII terminals. While it may produce a
less readable result, it's safer.
Thanks,
Kirill
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H