ironpython2.7中str函数不支持中文变量

 

我想说:
    其实ironpython2.7对中文支持的挺好
大家可以放心使用
但切记str()这个函数就不要用
如果里面有中文就无法解析
查了很多资料
都要动手改源代码了
以上使用 SharpDeverlop+Iconpython2.7测试

 

 

 

窗口是用SharpDeverlop的ipy设计器拉的。

大致的源码

class MyError(Exception):
    def __init__(self, value):
        self.value = value
    def __str__(self):
        return repr(self.value)

class RunAlt():
    import clr

    clr.AddReference('IronPython')
    from IronPython.Hosting import Python
    engine = Python.CreateEngine()
    scope = engine.CreateScope()    
    print '加载解析器'
    # scope.SetVariable("my_object_model", CallingPython())
    def __init__(self,str):
        self.Str=str
    def GetPy(self):
        return self.Str
    def    RunPy(self):
        #self.engine.Execute("print ''")
        try:
            source = self.engine.CreateScriptSourceFromString(self.Str)
            source.Execute(self.scope)
        except RunAlt.MyError as e:
            print 'My exception, value:', e.value
            
runAlt=RunAlt("print '调用'")    
runAlt.RunPy()
from System import Console
Console.Read()


posted @ 2011-10-19 00:12  SongSharp  阅读(1139)  评论(0编辑  收藏  举报