Example #1
0
 /// <summary>
 /// Executes python commands from the console.
 /// </summary>
 /// <param name="input"></param>
 /// <returns>Returns the execution results or error messages.</returns>
 public void Execute(string input)
 {
     try
     {
         if ((input != "") && ((input[input.Length - 1].ToString() == ":") || (multi != ""))) //multiline block incomplete, ask for more
         {
             multi += input + "\n";
             Console.Prompt(PromptCont, Execute);
         }
         else if (multi != "" && input == "") //execute the multiline code after block is finished
         {
             string temp = multi;             // make sure that multi is cleared, even if it returns an error
             multi = "";
             PythonEngine.Execute(temp);
             Console.WriteLine(getOutput());
             Console.Prompt(Prompt, Execute);
         }
         else // if (multi == "" && input != "") execute single line expressions or statements
         {
             PythonEngine.Execute(input);
             Console.WriteLine(Console.Chomp(getOutput()));
             Console.Prompt(Prompt, Execute);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("ERROR: " + ex.Message);
         Console.Prompt(Prompt, Execute);
     }
 }
Example #2
0
 /// <summary>
 /// Writes a line to the console
 /// </summary>
 /// <param name="s">String to write</param>
 public void WriteLine(string s)
 {
     Console.WriteLine(s);
 }