On 31 A ustos, 16:58, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Fri, 31 Aug 2007 12:53:36 +0000, Sönmez Kartal wrote: > > On 31 A ustos, 04:24, Steven Bethard <[EMAIL PROTECTED]> wrote: > >> Snmez Kartal wrote: > >> > I've had an encoding issue and solved it by > >> > "sys.setdefaultencoding('utf-8')"... > > >> > My first try wasn't successful since setdefaultencoding is not named > >> > when I imported sys module. After, I import sys module, I needed to > >> > write "reload(sys)" also. > > >> > I wonder why we need to call "reload(sys)" to get setdefaultencoding > >> > named? > > >> sys.setdefaultencoding is purposely deleted from the sys module after > >> it's loaded because you really shouldn't be using it. The reload() call > >> restores the deleted attribute. > > >> If you'd like a less brittle solution to your encoding issue, explain > >> what the issue was, and people here can probably help you find a better > >> solution. > > > 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... > > This doesn't help us that much. What is `f` here and what is `xml`? > > > This is the part of xmlbuilder.py which raises the error. > > > try: > > if self.pretty: > > # tabs are evil, so we will use two spaces > > outstr = self._dom.toprettyxml(" > > ",encoding=self.encoding) > > else: > > outstr = self._dom.toxml(encoding=self.encoding) > > except UnicodeDecodeError: > > sys.stderr.write('Decoding Error: You must configure > > default encoding\n') > > sys.exit() > > So there is an attribute `self.encoding` on that object. Is it set? What > encoding is it? And do you put byte strings with values outside ASCII > into your XML or unicode strings? > > Ciao, > Marc 'BlackJack' Rintsch
I should have said that 'f' is a file object and xml is a XMLBuilder object. Sorry. :-) self.encoding is 'utf-8' by default. I have only ® and characters in the XML file and a space character which Emacs shows as colored '_'. I have replaced those but didn't work! Here is the full code of xmlbuilder.py: http://rafb.net/p/9rURi822.html I don't wanna bother you but if you see there is something not practical then I'll keep writing about this. :-)
-- http://mail.python.org/mailman/listinfo/python-list