🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.python
Article #27383

minidom, UTF-8, zapis do pliku

#27383
From: quazar
Date: Thu, 18 Mar 2010 13:33
18 lines
2001 bytes
Witam.
Mam plik xml z nagłówkiem "<?xml version="1.0" encoding="UTF-8"?>",
odczytuję go za pomoca DOMTree = minidom.parse(xmlFile),
a następnie chcę strukturę DOMTree zapisać na dysku
xmlOut.write(DOMTree.toxml()).
Jeśli w pliku znajduja się tylko standardowe znaki ASCII to plik
powstaje, natomiast jeśli w pliku znajduje się jakaś pllitera to
dostaję klmunikat:
Traceback (most recent call last):
  File "C:\Documents and Settings\TNT\Moje dokumenty\NetBeansProjects
\NewPythonProject\src\xy2yx_xml.py", line 33, in <module>
     xmlOut.write(DOMTree.toxml())
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0141' in
position 20: ordinal not in range(128)

W jaki sposób mam sobie poradzić z tym problemem?

Darek Strojecki
Technical Details
Message-ID: <3adc299d-e0ee-45fd-93d0-4474acc80d1d@e7g2000yqf.googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!lublin.pl!uw.edu.pl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!feeder.news-service.com!postnews.google.com!e7g2000yqf.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!lublin.pl!uw.edu.pl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!feeder.news-service.com!postnews.google.com!e7g2000yqf.googlegroups.com!not-for-mail
From: quazar <dstroj@gmail.com>
Newsgroups: pl.comp.lang.python
Subject: minidom, UTF-8, zapis do pliku
Date: Thu, 18 Mar 2010 06:33:13 -0700 (PDT)
Organization: http://groups.google.com
Lines: 18
Message-ID: <3adc299d-e0ee-45fd-93d0-4474acc80d1d@e7g2000yqf.googlegroups.com>
NNTP-Posting-Host: 79.185.125.68
Mime-Version: 1.0
X-Trace: posting.google.com 1268919193 29296 127.0.0.1 (18 Mar 2010 13:33:13 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 18 Mar 2010 13:33:13 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: e7g2000yqf.googlegroups.com; posting-host=79.185.125.68;  posting-account=JIgnCAoAAAA-_73-PV6foQ-Pgxb14TTp
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.2)  Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729),gzip(gfe),gzip(gfe)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit