Unexpected token append

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

I wrote a simple language translator application using IronPython and I call the python code via a C# console application. I tested the python code separately and it works fine. However, when I call the python code via the C# application it always gives the Microsoft.Scripting.SyntaxErrorException: 'unexpected token 'append'' error message.

ScriptEngine engine = Python.CreateEngine(); ScriptSource source = engine.CreateScriptSourceFromFile(@"D:\Projects\Translator.py");  ICollection<string> Paths = engine.GetSearchPaths(); Paths.Add(@"C:\Program Files\Python37\Lib\"); Paths.Add(@"C:\Program Files\Python37\Lib\site-packages\"); engine.SetSearchPaths(Paths);  ScriptScope scope = engine.CreateScope(); source.Execute(scope);  dynamic GoogleTranslator = scope.GetVariable("GoogleTranslator"); dynamic gTranslator = GoogleTranslator(); gTranslator.SetInfo("'Привет, корова мальчик'"); var result = gTranslator.Translate();  Console.Write(result); Console.Read(); 

---------- Python Code -----------

from googletrans import Translator  class GoogleTranslator(object):     Text = ""     Dest  = ""      def SetInfo(self, text, dest = 'en'):         self.Text = text         self.Dest = dest      def Translate(self):         translator = Translator()         result = translator.translate(self.Text, self.Dest)         return result.text 

Can anyone tell me what is the issue with the code. The error generate from the "source.Execute(scope);"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!