[IronPython] Encoding problem

Michael Tan fantasysoft at hotmail.com
Wed Jan 4 15:56:12 CET 2006

Dear All,
    Here I am. :) This time, I have another silly problem about encoding of 
IronPython. According to my experience in programming, now IP can support 
unicode under interactive mode. If I put the unicode into .py file, the 
unicode code can not be displayed correctly.And I followed the Python 
Specification and tried to add the encoding declaration into .py file like 
     # -*- coding: utf-8 -*-
But this declaration doesn't work.
    I found that what results in the encoding problem. The fromFile method 
in Parser.cs is the key factor. Here is the source of fromFile method:
     public static Parser fromFile(CompilerContext context, string 
filename) {
            string data;
            // we choose ASCII by default, if the file has a Unicode header 
            // we'll automatically get it as unicode.
            StreamReader sr = new StreamReader(File.OpenRead(filename), 
            using (sr) {
                data = sr.ReadToEnd();
            return new Parser(context, filename, new Tokenizer(context, 
     I revised the System.Text.Encoding.ASCII to 
System.Text.Encoding.Default. The encoding problem was solved. I do hope 
receive the official comment about this revision. Thank you very much.


More information about the Ironpython-users mailing list