reload(sys)

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Sep 6 12:01:36 EDT 2007


On 6 sep, 08:13, Sönmez Kartal <rainwatch... at gmail.com> wrote:
> On 3 Eylül, 05:40, Steven Bethard <steven.beth... at gmail.com> wrote:
> > Sönmez Kartal wrote:
> > > I was using the XMLBuilder(xmlbuilder.py). I'm writing XML files as
> > > "f.write(str(xml))". At execution of that line, it gives error with
> > > description, configure your default encoding...
>
> > Can you show the code where you populate the XMLBuilder? I'm guessing
> > you're doing something like::
> >      import xmlbuilder
> >      builder = xmlbuilder.XMLBuilder()
> >      builder.foo = dict(bar='® and ™')
> >      str(builder)
>
> > That breaks because the string '® and ™' is not properly encoded. Have
> > you declared an encoding in your source file? PEP 263 shows you how:

> http://rafb.net/p/RfaF8215.html
>
> products in the code is a list of dictionaries which are returned by
> makeProduct function.
>
> I'm not typing or pasting those characters into my script. So,
> declaring an encoding didn't make it. :-( But, your code excerpt
> runned well.

You should ensure that arguments to makeProduct are either:
- unicode objects
- ASCII strings

If you got them from some other place, decode the strings as soon as
possible into unicode. Read <http://www.amk.ca/python/howto/unicode>
to understand what's happening (and why the XMLBuilder error message
is *not* a good advice)

--
Gabriel Genellina




More information about the Python-list mailing list