Running IronPython Scripts from a C# 4.0 Program


 

Running IronPython Scripts from a C# 4.0 Program

Before you read this you may want to check out my other post.

IronPython is a scripting language hosted on the .NET platform. This posts shows how you can use the Dynamic Language Runtime (DLR) and the new C# 4.0 dynamic keyword to call an IronPython script from a C# program.

image

Test.py

import sys

def Simple():
    print "Hello from Python"
    print "Call Dir(): "
    print dir()
    print "Print the Path: " 
    print sys.path

 

using System;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;

public class dynamic_demo
{
    static void Main()
    {
        var ipy = Python.CreateRuntime();
        dynamic test = ipy.UseFile("Test.py");
        test.Simple();
    }
}

image

Via Charlie Calvert’s Community Blog : Running IronPython Scripts from a C# 4.0 Program

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s