On 3 Eylül, 05:40, Steven Bethard <[EMAIL PROTECTED]> 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... > > [and later] > > > I get this when it happens: "Decoding Error: You must configure > > default encoding" which comes from in the code excerpt in > > xmlbuilder.py (http://rafb.net/p/9rURi822.html) > > 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://www.python.org/dev/peps/pep-0263/ > > Note that with Python 2.5 the code above gives a SyntaxError without a > proper encoding. You should also probably be prefixing your string > literals containing weird characters with "u" to make them unicode. > Doing both of these in the code above made it work for me. > > STeVe
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. I have tried "f.write(unicode(xml))" for the last line of the script. No success. I think we should think about how we can achieve the effect of "sys.setdefaultencoding('utf-8')"
-- http://mail.python.org/mailman/listinfo/python-list