Python for .NET and IronPython

J

John Salerno

Hi all. I'm currently learning C#, and I'm also interested in learning
Python (all of this just for fun, mind you), so it seems like a decent
idea to want to integrate the two. But I don't quite understand the
difference between these two Python implementations and I was hoping
someone could explain.

Does either one require learning something different than the core
Python language? With IronPython, would you actually be writing .NET
code? I know Python for .NET is treated as a true language in the CLR,
but I don't quite grasp what all this means for each language, and what
the learning process for either language would be like as a result.

Thanks,
John
 
J

John Salerno

John said:
code? I know Python for .NET is treated as a true language in the CLR,
but I don't quite grasp what all this means for each language

isn't* treated, I meant to say!
 
S

Steve M

I was under the impression that IronPython is like CPython and Jython,
namely an implementation of the Python language. So in that sense it is
exactly like normal Python, although I don't know how convenient it is
to deploy.

I was also under the impression that Python for .NET is like an API
wrapper thingy, analagous to the win32com package that wraps that
interface and allows you to call functions and stuff provided by the
..NET API. It is not at all an implementation of Python.

I am confident that we will learn shortly whether I'm wrong.
 
H

hrh1818

For more information on Iron Python see http://www.ironpython.com/
My take on Iron Python is the new job the develolper of Iron Python
started last year takes up just about all of his time and the developer
is currently spending very little time actively developing Iron Python.
I suspect it will be a long time before Iron Python will be a main
stream product. Hence I suggest you spend your time learning Python and
C# and you forget about Iron Python until it is more fully developed.


Howard
 
J

James

IronPython is good if you want to bring in Python into a .NET world.

Python for .NET is good if you want to bring in .NET into a Python
world.

As for your learning concerns, there need be none. There is really
nothing to learn extra for the integration. They just work. Once you
learn the .NET framework and Python, there isn't much to know
additionally.

While you are on topic, check out Boo. It is not the same as the ones
you mentioned but you might find it interesting and useful while
working with .NET if you have Python tastes.
 
B

Brett Hoerner

hrh1818 said:
For more information on Iron Python see http://www.ironpython.com/
My take on Iron Python is the new job the develolper of Iron Python
started last year takes up just about all of his time and the developer
is currently spending very little time actively developing Iron Python.

Actually, he just stopped updating ironpython.com (a bad idea, imo)
apparently.

Last release was 10/13 through Microsoft,
http://www.microsoft.com/downloads/...e3-6495-427f-8b1f-768a2715170c&DisplayLang=en

If that link doesn't work you can just search "IronPython" on
microsoft.com

Brett
 
A

Alex Martelli

hrh1818 said:
For more information on Iron Python see http://www.ironpython.com/
My take on Iron Python is the new job the develolper of Iron Python
started last year takes up just about all of his time and the developer
is currently spending very little time actively developing Iron Python.
I suspect it will be a long time before Iron Python will be a main
stream product. Hence I suggest you spend your time learning Python and
C# and you forget about Iron Python until it is more fully developed.

According to the guy who came present IronPython at EURO OScon, there's
now 1.5 people (both MS employees) working on IronPython -- the
presenter himself, fulltime, and Jim Hugunin, halftime. The language is
just about ready (with a few last decisions to make, such as, stick to
unicode-only strings like Jython, or strive for greater practical
compatibility with current CPython?); it passes the CPython unit-tests,
with a few adjustments needed where the tests overspecify some aspects
of behavior compared to the Language Manual.

What's missing is a lot of the Python standard library -- most of the
parts that are written in C in CPython (and, I believe, in Java in
Jython). My impression is that the realistic timeframe to implement
those is several months; meanwhile, IronPython is usable if you're
willing to make direct calls to the standard MSCLR libraries (i.e.,
forego ease of future moves to CPython).

A beginner might be best advised to stick with CPython (and, if DotNet
is needed, perhaps the Python-like language Boo) while IronPython
stabilizes and fleshes out, but I'm rather more optimistic than you
about the speed with which that will happen.


Alex
 
G

Gerard Flanagan

John said:
Hi all. I'm currently learning C#, and I'm also interested in learning
Python

In a similar position to yourself - learning both languages - I can
definitely recommend Python ( though C# 's curly brackets might annoy
you more than they did before!!)
so it seems like a decent
idea to want to integrate the two

FWIW, what I've been doing lately is calling Python scripts from
Windows.Forms apps, capturing their 'StdOut'. There's an article on
http://www.thecodeproject.com which explains how you can do this
asynchronously, but the following (C#) code is what I'm using ( imagine
a Windows Form with a TextBox to enter the script name, another to
enter any arguments for the script, and 'Run', 'Cancel' and 'Browse'
CommandButtons).


(assumes the script requires no user interaction)

private void BrowseForScript_Click(object sender, System.EventArgs e)
{
if ( this.openFileDialog.ShowDialog() == DialogResult.OK )
{
this.txtIO.Clear();
this.txtIO.Focus();
this.txtIO.AppendText( openFileDialog.FileName);
}
}

private void Run_Click(object sender, System.EventArgs e)
{
System.Diagnostics.ProcessStartInfo startInfo;
System.Diagnostics.Process process;
string directory;
string pyArgs;
string script;

script = this.txtIO.Text.Trim();

if ( script == null || script.Length == 0 )
{
return;
}

try
{
directory = Path.GetDirectoryName( script );
script = Path.GetFileName( script );
}
catch (ArgumentException)
{
MessageBox.Show("The script file path contains invalid characters.",
"Invalid Script Path",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}

if ( script.Length == 0 )
{
MessageBox.Show("No script file has been specified.",
"Invalid Script Path",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}

if ( directory == null || directory.Length == 0 )
{
directory = DEFAULT_SCRIPT_DIRECTORY;
}

pyArgs = this.txtArgs.Text.Trim();

startInfo = new ProcessStartInfo("python");
startInfo.WorkingDirectory = directory;
startInfo.Arguments = script + " " + pyArgs;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;

process = new Process();
process.StartInfo = startInfo;
process.Start();

string s;
while ((s = process.StandardOutput.ReadLine()) != null)
{
this.__application.Write( s + "\n" );
}

while ((s = process.StandardError.ReadLine()) != null)
{
this.__application.Write( s + "\n" );
}
}


Gerard
 
L

Luis M. Gonzalez

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top