🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.python
2 messages
2 total messages Started by quazar Thu, 18 Mar 2010 13:33
minidom, UTF-8, zapis do pliku
#27383
Author: 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
Re: minidom, UTF-8, zapis do pliku
#27384
Author: Jordan Szubert
Date: Thu, 18 Mar 2010 18:02
6 lines
1285 bytes
Dnia 18-03-2010 o 14:33:13 quazar <dstroj@gmail.com> napisał(a):

[...]
-      xmlOut.write(DOMTree.toxml())
+      xmlOut.write(DOMTree.toxml(encoding='utf-8'))
[...]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads