Python nuube needs Unicode help
Diez B. Roggisch
deets at nospam.web.de
Fri Jan 12 09:48:16 EST 2007
gheissenberger at gmail.com wrote:
> Can you attach files in this forum? Couldn't find the option. Oh well,
> here's the file.
>
> #!/usr/bin/python
> # Version: 1.1
> # Author: Steve Losh
>
> from sets import Set
> from optparse import OptionParser
> from xml.dom.minidom import parse
>
> AudioPath = 'audio/'
> DatafilePath = 'utterances.trmxml'
> CONFIDENCE_LOW = None #'500'
> CONFIDENCE_HIGH = None #'500'
>
> utterancesFile = None
>
>
> class Utterance:
> def __init__(self, audio, grammarSet, text):
> self.audio = audio
> self.grammarSet = grammarSet
> self.text = text
>
> def __str__(self):
> return "SWIrecAcousticStateReset\ntranscription " + self.text \
> + "\nrecognize " + AudioPath + self.audio
There your __str__-method is. self.text and self.audio come from the
xml-parsing and are unicode objects - so they need to be encoded, like
this:
def __str__(self):
return "SWIrecAcousticStateReset\ntranscription " +
self.text.encode('utf-8') + "\nrecognize " + AudioPath +
self.audio.encode('utf-8')
Diez
More information about the Python-list
mailing list