[IronPython] CLR class constructors and arrays
John Messerly
jomes at microsoft.com
Tue Jul 31 00:20:14 CEST 2007
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
More information about the Ironpython-users
mailing list