ironpython2.7中str函数不支持中文变量
我想说:
其实ironpython2.7对中文支持的挺好
大家可以放心使用
但切记str()这个函数就不要用
如果里面有中文就无法解析
查了很多资料
都要动手改源代码了
以上使用 SharpDeverlop+Iconpython2.7测试
其实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()
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()
![](http://www.cnblogs.com/images/cnblogs_com/songsharp/SongSharp.jpg)
如有不足的地方欢迎提点!谢谢!
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。