Iron Python NewB questions . . .

View: New views
7 Messages — Rating Filter:   Alert me  

Iron Python NewB questions . . .

by Frank Merrow :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

So I've been reading the Iron Python docs plus installed and played
with it a little bit . . . it doesn't look like Iron Python does
quite what I need.

If I have a Python script . . . and I want to access a C# assembly .
. . it looks like I am Golden.  (I have yet to actually get it to
work, but it looks like the pieces are there.)

However, if I want to create a Python .NET assembly so I can call an
existing Python class set from C# . . . it looks to me like that
direction doesn't exist.

The other thing that I see here, is that even if I adopt the "Python
on top" philosophy . . . since I cannot create an assembly . . . I
cannot create an executable file and I think also that things like
Py2EXE and PyInstaller won't work either.

That is . . . to run the resulting scripts, I have to install Iron
Python on every target system.  (Currently we wrap our application
using PyInstaller and so the customer does not have to have Python
installed to run it.)

Lastly, I'm wondering is any of this is runnable under Unix Mono . .
. I'm guessing the answer is "no".

Comments welcomed.

If I have misunderstood anything here . . . please point me at docs
so I can do more reading.

Frank

_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: Iron Python NewB questions . . .

by Dino Viehland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Frank wrote:

> So I've been reading the Iron Python docs plus installed and played
> with it a little bit . . . it doesn't look like Iron Python does
> quite what I need.
>
> If I have a Python script . . . and I want to access a C# assembly .
> . . it looks like I am Golden.  (I have yet to actually get it to
> work, but it looks like the pieces are there.)
>
> However, if I want to create a Python .NET assembly so I can call an
> existing Python class set from C# . . . it looks to me like that
> direction doesn't exist.

There's a couple of ways to do this.  You can define an interface or base
class on the C# side and implement it on the Python side.  Then you can
cast the Python object to the interface or base class and use it that way.

Also w/ .NET 4.0 C# is getting the new static type "dynamic" which can
be used for interoperating with Python and other objects which respond
dynamically.  VB.NET, while already having dynamic support, also gets
updated so that it can consume IronPython and IronRuby objects.

>
> The other thing that I see here, is that even if I adopt the "Python
> on top" philosophy . . . since I cannot create an assembly . . . I
> cannot create an executable file and I think also that things like
> Py2EXE and PyInstaller won't work either.
>
> That is . . . to run the resulting scripts, I have to install Iron
> Python on every target system.  (Currently we wrap our application
> using PyInstaller and so the customer does not have to have Python
> installed to run it.)

In the Tools\Scripts directory of the installation is a script called
pyc.py which can be used to compile Python code into a DLL or an EXE.
The resulting code still needs the IronPython libraries but it provides
a way to pre-compile the code (including down to native code using ngen)
and to not distribute the actual Python code.

> Lastly, I'm wondering is any of this is runnable under Unix Mono . .
> . I'm guessing the answer is "no".

IronPython does run on Mono under Unix.  Occasionally we break them but
the Mono team is usually pretty fast to respond to issues reported and
fix them.  I'm not sure what the current status is so you may need to
use the latest SVN for it to work.


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: Iron Python NewB questions . . .

by Seo Sanghyeon-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/10/31 Frank Merrow <fmerrow@...>:
> Lastly, I'm wondering is any of this is runnable under Unix Mono . . . I'm
> guessing the answer is "no".

The answer is definitely "yes". I run it daily.

I am not sure what documentation are you looking for. Do you want
something from Microsoft? Then I am not sure whether such thing exists
(or should exist). On the other hand, Mono project website clearly
says "Mono supports IronPython", and it is one of their goal to stay
that way.

http://mono-project.com/Python

--
Seo Sanghyeon
_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: Iron Python NewB questions . . .

by Frank Merrow :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


>There's a couple of ways to do this.  You can define an interface or base
>class on the C# side and implement it on the Python side.  Then you can
>cast the Python object to the interface or base class and use it that way.

Well . . . I was not able to "cast" this into anything . . . they are
very different interfaces.

I eventually started looking at the module pyc.py output in the
Object Browser and trying to use it . . . not much information on the
Internet for DLRCachedCode . . . and what does exist is . . . well
over my head.  Reminds me of the old days trying to call a DCOM
object from C++ . . . was ugly, ugly code . . . this looks similar .
. . and in the face of the much nicer option below, in true Monte
Python style I decided to "run away".

>Also w/ .NET 4.0 C# is getting the new static type "dynamic" which can
>be used for interoperating with Python and other objects which respond
>dynamically.  VB.NET, while already having dynamic support, also gets
>updated so that it can consume IronPython and IronRuby objects.

Yeah, docs for this look MUCH NICER . . . I'm downloading the Beta's
now to give this a try.

If this works . . . I'll hang my hat on VS2010 and .NET 4.0 and hope
I've never forced to look back.

Thanks for the info.

Frank


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: Iron Python NewB questions . . .

by Justin Regele :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Embedding IPy in C# isn't easy at first, and definitely not super straight-forward, but there are alot of options of how to do it. Get Mike's book, or at least download the source for the embedding chapter. Embedding ironpython is tricky now, but things are progressing quickly, and there ARE lots of ways to do it--different techniques for different situations.



On Mon, Nov 2, 2009 at 12:27 PM, Frank Merrow <fmerrow@...> wrote:

There's a couple of ways to do this.  You can define an interface or base
class on the C# side and implement it on the Python side.  Then you can
cast the Python object to the interface or base class and use it that way.

Well . . . I was not able to "cast" this into anything . . . they are very different interfaces.

I eventually started looking at the module pyc.py output in the Object Browser and trying to use it . . . not much information on the Internet for DLRCachedCode . . . and what does exist is . . . well over my head.  Reminds me of the old days trying to call a DCOM object from C++ . . . was ugly, ugly code . . . this looks similar . . . and in the face of the much nicer option below, in true Monte Python style I decided to "run away".


Also w/ .NET 4.0 C# is getting the new static type "dynamic" which can
be used for interoperating with Python and other objects which respond
dynamically.  VB.NET, while already having dynamic support, also gets
updated so that it can consume IronPython and IronRuby objects.

Yeah, docs for this look MUCH NICER . . . I'm downloading the Beta's now to give this a try.

If this works . . . I'll hang my hat on VS2010 and .NET 4.0 and hope I've never forced to look back.

Thanks for the info.


Frank


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: Iron Python NewB questions . . .

by Frank Merrow :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

At 01:43 PM 11/2/2009, Justin Regele wrote:
>Embedding IPy in C# isn't easy at first, and definitely not super
>straight-forward, but there are alot of options of how to do it. Get
>Mike's book, or at least download the source for the embedding
>chapter. Embedding ironpython is tricky now, but things are
>progressing quickly, and there ARE lots of ways to do it--different
>techniques for different situations.

Okay, maybe everyone on this list knows, but I don't . . .

Mike Who and what book?

Frank

_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: Iron Python NewB questions . . .

by Dave Purrington-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Mike in this case is probably Michael Foord. http://www.ironpythoninaction.com/

Here's a good place to start (from Mike's blog): http://www.voidspace.org.uk/ironpython/hosting_api.shtm

There are lots of variations of hosting, and many patterns. Sounds like you might be wanting to define classes in IPy and instantiate them. Basically, you run the script that defines the class, then get the class object from the runtime scope, then invoke the constructor which returns an instance of the object. Casting should work in that case (provided of course that you've derived from the type in question). For example:

        public T Load<T>(string path, params object[] parameters) where T : class {

                ScriptSource script = _engine.CreateScriptSourceFromFile(path);
                CompiledCode code = script.Compile();
                string className = Path.GetFileNameWithoutExtension(path); # this is just a convention
                object theClass = _scope.GetVariable(className);
                object instance = _engine.Operations.Invoke(theClass, parameters);
                return instance as T;
    }

This isn't the only info you need, but should give you an idea of how it works. Try searching for "ironpython hosting"

Hope this helps.

On Mon, Nov 2, 2009 at 4:59 PM, Frank Merrow <fmerrow@...> wrote:
At 01:43 PM 11/2/2009, Justin Regele wrote:
Embedding IPy in C# isn't easy at first, and definitely not super straight-forward, but there are alot of options of how to do it. Get Mike's book, or at least download the source for the embedding chapter. Embedding ironpython is tricky now, but things are progressing quickly, and there ARE lots of ways to do it--different techniques for different situations.

Okay, maybe everyone on this list knows, but I don't . . .

Mike Who and what book?


Frank

_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com