IronPython : Microsoft.Scripting.SyntaxErrorException: 'unexpected token '=''

假如想象 提交于 2021-02-08 06:20:09

问题


I have a Python scrirpt and that I am trying to execute from C# code using IronPython and I am getting the below error message:

Microsoft.Scripting.SyntaxErrorException: 'unexpected token '=''

Here is my Python code:

import logging
logging.basicConfig(filename='c:\\rahul\\example.log',level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')

BUCKET_NAME='Rahul'
print("Bucket name :-" + BUCKET_NAME)

And here is my .NET C# code:

var engine = Python.CreateEngine(); 
var searchPaths = engine.GetSearchPaths();
searchPaths.Add(@"C:\Users\rahul\appdata\Local\Programs\Python\Python37-32\Lib");
engine.SetSearchPaths(searchPaths);
var scope = engine.CreateScope();
ScriptSource source = engine.CreateScriptSourceFromFile(filePath);
var compiled = source.Compile();
var result = compiled.Execute(scope);

I am getting an error from the last line :

Microsoft.Scripting.SyntaxErrorException: 'unexpected token '=''

Any help?

来源:https://stackoverflow.com/questions/53535931/ironpython-microsoft-scripting-syntaxerrorexception-unexpected-token

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