[IronPython] Return value from Execute()

Mark Senko msenko at completegenomics.com
Mon Oct 11 21:53:24 CEST 2010

So simple! Casting to IEnumerable worked great!

Maybe I should have mentioned that I'm relatively new to C#, too.
I didn't realize you could cast to an interface, though now that I think
about it, it makes perfect sense.

Thank you, Jeff.

-----Original Message-----
From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of Jeff Hardy
Sent: Monday, October 11, 2010 12:10 PM
To: Discussion of IronPython
Subject: Re: [IronPython] Return value from Execute()

On Mon, Oct 11, 2010 at 11:40 AM, Mark Senko
<msenko at completegenomics.com> wrote:
> But I've had an impossible time trying to figure out how to iterate
over an
> IronPython.Runtime.List as returned by a command such as dir() since
> seems to not be enumerable.
> Typecasting this object doesn't to an array or a List<> doesn't seem
> work.

Have you tried casting to IEnumerable? That has always* worked for me.

    var _pythonRes = source.Execute(_pscope);
    if(_pythonRes is IEnumerable) { ... }

Or, in C# 4, you should be able to make _pythonRes dynamic:
    dynamic _pythonRes = source.Execute(_pscope);
    foreach(dynamic r in _pythonRes) { ... }

Whichever works better for you.

- Jeff

* There used to be some bugs, but they should be long gone.
Users mailing list
Users at lists.ironpython.com

The contents of this e-mail and any attachments are confidential and only for 
use by the intended recipient. Any unauthorized use, distribution or copying 
of this message is strictly prohibited. If you are not the intended recipient 
please inform the sender immediately by reply e-mail and delete this message 
from your system. Thank you for your co-operation.

More information about the Ironpython-users mailing list