1

Possible Duplicate:
Instantiating a python class in C#
Embedding IronPython in C#

I trying this: link

C#:

private void Form1_Load(object sender, EventArgs e)
{
    var ipy = Python.CreateRuntime();
    dynamic test = ipy.UseFile(@"C:\Users\Admin\Desktop\Test.py");
    textBox1.Text = test.Simple();
}

Python:

def Simple():
    print "Hello from Python"

No error, when I run it, the textbox remain blank. What I doing wrong?

Community
  • 1
  • 1
a1204773
  • 6,923
  • 20
  • 64
  • 94
  • 1
    Don't know Python, but should not you return something from `Simple` function instead of just `print` ? – Alexei Levenkov Nov 15 '12 at 23:46
  • @AlexeiLevenkov That is true, the link that he got the example from is printing to a console window. He should be using `return "Hello from Python"` instead. – matthewr Nov 15 '12 at 23:47
  • yes guys you absolutely right... I though c# take the output of cmd and pass it to c#... Thanks for help – a1204773 Nov 15 '12 at 23:50
  • Converted my comment into answer. @KirkWoll, I don't think it is dup as the linked question is talking about how to actually do that, but not why particular method Python returns nothing. – Alexei Levenkov Nov 15 '12 at 23:55
  • @AlexeiLevenkov, I guess you're right. I was just thrown by the fact that when I tried to fix the spelling error in the OP's title, it wouldn't let me because of the existing question. :) – Kirk Woll Nov 16 '12 at 00:10

1 Answers1

2

Your Simple function does not return anything, it just prints output to console with print. Something like return "Hello from Python" should give you results you want.

Side note: you may be able to intercept console output, but it would probably not what you are interested in.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179