IronPython:Microsoft.Scripting.SyntaxErrorException:'意外的令牌'=''

时间:2018-11-29 09:40:50

标签: c# python .net syntax-error ironpython

我有一个python脚本,我正在尝试使用IronPython从C#代码执行,并且收到以下错误消息:

  

Microsoft.Scripting.SyntaxErrorException:'意外令牌'='

这是我的Python代码:

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)

这是我的.NET C#代码:

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);

我从最后一行得到一个错误:

  

Microsoft.Scripting.SyntaxErrorException:'意外令牌'='

有帮助吗?

0 个答案:

没有答案