<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><DIV>Hi to all,</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>I scripted some text files with another language which cannot handle unicode.</DIV><DIV>As I need special character in the resulting text files (IPA extension), my idea was to define some special ascii sequences in the text files, open the text files in Python, replace the special sequences with unicode and encode in utf8. I made some tests with consolle and everything seemed fine.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>But my script keeps on raising exceptions related to encoding.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Sorry if it's obvious but I really can't figure out what to do.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>The script follows.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Thanks a lot</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>-a-</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV># a class for replacing ascii with unicode</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>import codecs</DIV><DIV>import os</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>class Unicoder:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>        def __init__(self, folder):</DIV><DIV>            files = os.listdir(folder)</DIV><DIV>            paths = []</DIV><DIV>            for x in files:</DIV><DIV>                paths.append(folder+"/"+x)</DIV><DIV>            self.files = paths            </DIV><DIV>            # a list containing all the sc-generated .ly files</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>        def intoText(self, inFile):</DIV><DIV>            aFile = codecs.open(inFile, "r")</DIV><DIV>            text = aFile.read() # read all its content in text</DIV><DIV>            return text</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>        def replaceSpecials(self, text):</DIV><DIV>            replacementDict = (</DIV><DIV>            {"[O]":u"\u0254",</DIV><DIV>             "[U]":u"\u0277",</DIV><DIV>             "[E]":u"\u025b",</DIV><DIV>             "[o|]":u"\xf8",</DIV><DIV>             "[oe]":u"\u0153",</DIV><DIV>             "[e:]":u"\u0259",</DIV><DIV>             "[I]":u"\u026a",</DIV><DIV>             "[ae]":u"\xe6",</DIV><DIV>             "[A]":u"\u0251",</DIV><DIV>             "[Q]":u"\u0252",</DIV><DIV>             "[V]":u"\u028c"                </DIV><DIV>             }</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>            )</DIV><DIV>            # hash table where to look up for replacement</DIV><DIV>            for ascii in replacementDict:</DIV><DIV>                print ascii</DIV><DIV>                utf = replacementDict[ascii]</DIV><DIV>                text = text.replace(ascii, utf.encode("utf-8"))</DIV><DIV>            return text</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>        def toFile(self, text, outFileName):</DIV><DIV>            outFile = codecs.open(outFileName, encoding='utf-8', mode="w")</DIV><DIV>            outFile.write(text)</DIV><DIV>            outFile.close()</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>        def run(self):</DIV><DIV>            for aFileName in self.files:</DIV><DIV>                outFileName = aFileName.split(".")[0]+"UTF.ly"</DIV><DIV>                text = self.intoText(aFileName)</DIV><DIV>                text = self.replaceSpecials(text)</DIV><DIV>                self.toFile(text, outFileName)</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>if __name__ == "__main__":</DIV><DIV>    a = Unicoder("/musica/antigone/scores/")</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV># EOF</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><DIV>--------------------------------------------------</DIV><DIV>Andrea Valle</DIV><DIV>--------------------------------------------------</DIV><DIV>CIRMA - DAMS</DIV><DIV>Università degli Studi di Torino</DIV><DIV>--> <A href="http://www.cirma.unito.it/andrea/">http://www.cirma.unito.it/andrea/</A></DIV><DIV>--> <A href="mailto:andrea.valle@unito.it">andrea.valle@unito.it</A></DIV><DIV>--------------------------------------------------</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV> <FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;"><I>I did this interview where I just mentioned that I read Foucault</I></SPAN></FONT><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;"><I>. Who doesn't in university</I></SPAN></FONT><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;"><I>, right? I was in this strip club</I></SPAN></FONT><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;"><I> giving this guy a lap dance</I></SPAN></FONT><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;"><I> and all he wanted to do was to discuss Foucault with me. Well, I can stand naked and do my little dance, or I can discuss Foucault, but not at the same time; too much information.</I></SPAN></FONT><DIV><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;">(Annabel Chong)</SPAN></FONT></DIV><BR class="khtml-block-placeholder"></DIV></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV></BODY></HTML>