[IronPython] Embedding & Charsets

Igor Elyas igor_elyas at hotmail.com
Wed Mar 25 20:17:08 CET 2009


Hello

I'm use IronPython 2.0.1 as embedded interpreter for read data from database.
Code for create Engine:

            fEngine = Python.CreateEngine();
            Ops = fEngine.CreateOperations();
            // core libs
            fEngine.Runtime.LoadAssembly(typeof(Decimal).Assembly); 
            fEngine.Runtime.LoadAssembly(typeof(IValue).Assembly);            

            // loading ADO.NET driver assemblies
            LoadAssemblies(from v in EtlBaseCfg.BaseCfg.Element("dlls").Elements("dll") select v.Value);

After that, I use generated Ipy class for read one value from specific IDbDataReader:

from ETL.Common.pipes import IValuePipe
class SelectExtractor(IValuePipe):
    def __init__(self,adoreader,originId,storage):
        self._name = originId
        self._reader = adoreader
        self._idx = adoreader.GetOrdinal(self._name)
        self._transport = storage
    def Do(self, pydict):
        val = self._transport.Clone()
        if not self._reader.IsDBNull(self._idx):
            val.Data = self._reader.GetString(self._idx)
        if pydict.ContainsKey(self._name):
            pydict[self._name] = val
        else:
            pydict.Add(self._name,val)

This operation return string with Russian symbols and I get Exception: "'ascii' codec can't decode byte 0 in position 0: ordinal not in range"
How I can enable unicode .NET strings ?
Looks like I not initialize IronPython correctly, because this code in Ipy console work fine with Russian charset (Russian Windows), but not sure about other charsets. I need use .NET unicode strings.
Best regards

Igor Elyas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20090325/7625e5c0/attachment.html>


More information about the Ironpython-users mailing list