IronPython dependencies for scripts stored as strings

后端 未结 2 970
挽巷
挽巷 2020-12-17 06:37

I have a C# application that stores python script files (*.py) as strings. I load them using:

scriptEngine.CreateScriptSourceFromString(code);
2条回答
  •  無奈伤痛
    2020-12-17 07:07

    You could create the different scripts as one function each and call those functions based on arguments given

    ScriptScope scope = scriptEngine.CreateScope();
    
    scope.SetVariable("language", "en");
    
    scriptEngine.Execute(scope);
    

    and the python (silly example I know):

    def doEnStuff():
      print "english"
    
    def doEsStuff():
      print "espagna"
    
    if language == "en"
      doEnStuff()
    

提交回复
热议问题