GithubHelp home page GithubHelp logo

Comments (4)

slozier avatar slozier commented on July 28, 2024 1

The command line and C# program could have different default encodings. What value does f.encoding give you?

Is your file really using the cp949 encoding? If not you could pass in an explicit encoding, for example if it's utf-8: open(path, 'r', encoding='utf-8').

cp949 is not available because we don't have an implementation for _codecs_kr. Related issue: IronLanguages/ironpython2#659

from ironpython3.

nalsandori avatar nalsandori commented on July 28, 2024
  • I excuted the following commands in each program respectively.
    >>>sys.getdefaultencodnig() --> 'utf_8'

  • The same results were displayed on both the ironpython console and c# program

  • The following code also causes an encoding error in c# program(based on ironpython 3.4.1)
    os.popen(uabswitchcmdpath + ' -v').read()
    --> the above command worked fine in a c# program based on ironpython 2.7.9

  • Here is the c# initialize code

var runtime = IronPython.Hosting.Python.CreateRuntime();
runtime.IO.SetErrorOutput(streamwriter, Encoding.Default);
runtime.IO.SetOutput(streamwriter, Encoding.Default);
runtime.IO.SetInput(streamwriter, Encoding.Default);

from ironpython3.

slozier avatar slozier commented on July 28, 2024

sys.getdefaultencoding() is not the encoding used by open. You can use locale.getpreferredencoding(False) to get that value, or open(filename).encoding.

You could also try utf-8 mode which causes open to default to utf-8:

var runtime = IronPython.Hosting.Python.CreateRuntime(new Dictionary<string, object> { { "Utf8Mode", true } });

from ironpython3.

nalsandori avatar nalsandori commented on July 28, 2024

Thank you very much for your kind explanation.
The c# code has been helpful to me

from ironpython3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.