[IronPython] CLR class constructors and arrays

Eric Rochester erochest at gmail.com
Tue Jul 31 12:19:54 CEST 2007


It's not a problem at all.

I was just trying to test the API for a library from the interactive
interpreter. When it happened, I remembered that it had bit me before, and
this time I just happened to be in a mood to track it down.

Thanks,
Eric

On 7/30/07, John Messerly <jomes at microsoft.com> wrote:
>
> For what it's worth, this appears to be fixed in IronPython 2.0 alpha 3:
>
> >ipy paramcalltest.py
> args = System.String[]('a', 'b', 'c')
> creating ParamCall object:
> pc.Joined() => a,b,c
>
> If it's really bothersome we could add it to the 1.1.1 bug list, but in
> the meantime I'd suggest the workaround Michael mentioned (wrapping the args
> up in the tuple)
>
> Cheers,
> John
>
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:
> users-bounces at lists.ironpython.com] On Behalf Of Eric Rochester
> Sent: Monday, July 30, 2007 1:37 PM
> To: IronPython Users
> Subject: [IronPython] CLR class constructors and arrays
>
> Hi,
>
> I've been using IronPython for a few months now, and I'm really enjoying
> it. Thanks for all the hard work that's gone into it.
>
> I recently ran across an issue, and I wondered if anyone else has seen it.
> I think it's probably a bug, but I couldn't find a bug report, either.
>
> Basically, if there is a CLR class that takes an array as its only
> constructor argument, IronPython always tries to call it using params. For
> example, if I compile this to ParamCall.dll:
> // ParamCall.cs
>
> using System;
>
> namespace ParamCall
> {
>     public class ParamCall
>     {
>         private string[] args;
>
>         public ParamCall(string[] args)
>         {
>             this.args = args;
>         }
>
>         public string Joined()
>         {
>             return String.Join(",", args);
>         }
>     }
> }
>
> And I call it using this script:
> # paramcall.py
>
> import clr
> clr.AddReference('ParamCall')
>
> from ParamCall import ParamCall
> from System import Array
>
> args = Array[str]( ['a', 'b', 'c'] )
> print 'args =', args
>
> print 'creating ParamCall object:'
> pc = ParamCall(args)
> print 'pc.Joined() =>', pc.Joined()
>
> print
>
> I get these results.
> C:\home\eric\src\ase\Lse.Net>IronPython\ipy paramcall.py
> args = System.String[]('a', 'b', 'c')
> creating ParamCall object:
> Traceback (most recent call last):
>   File C:\home\eric\src\ase\Lse.Net\paramcall.py, line 7, in Initialize
>   File , line 0, in __import__##4
>   File C:\home\eric\src\ase\Lse.Net\ParamCall.py, line 15, in Initialize
>   File , line 0, in NonDefaultNew##54
> TypeError: ParamCall() takes exactly 1 argument (3 given)
>
> I have also tried wrapping the arguments in a tuple and calling it like
> ParamCall( *(args,) ), but the results are the same.
>
> If anyone has any suggestions for work-arounds or clues as to what I'm
> doing wrong, I'd be glad to hear them.
>
> Thanks,
>
> --
> Eric Rochester
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>



-- 
Eric Rochester
http://writingcoding.blogspot.com/
http://www.linkedin.com/in/erochester
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20070731/d6e7d81b/attachment.html>


More information about the Ironpython-users mailing list