[Ironpython-users] DynamicObjects.TryConvert not called in IronPython?

zxpatric zxpatric at gmail.com
Fri Jun 24 23:24:17 CEST 2011


Thanks Dino for the explanation.

float(obj.M1.M2.M3) leads to Message: 'xxx' object has no attribute
'__float__'
clr.Convert(obj.M1.M2.M3, float) *does *work.

Interesting observation:

For imported .NET function C.SetFloat(float a), C.SetFloat(obj.M1.M2.M3)
won't trigger the conversion as well.


On Fri, Jun 24, 2011 at 4:17 PM, Dino Viehland <dinov at microsoft.com> wrote:

>  In IronPython an assignment to a local/global variable will never perform
> a conversion.  In your C# code the conversion has to happen because the
> variable you’re assigning to is typed as double.  ****
>
> ** **
>
> To force the conversion you should be able to do float(obj.M1.M2.M3) or you
> can use the clr.Convert function.****
>
> ** **
>
> *From:* ironpython-users-bounces+dinov=microsoft.com at python.org [mailto:
> ironpython-users-bounces+dinov=microsoft.com at python.org] *On Behalf Of *
> zxpatric
> *Sent:* Friday, June 24, 2011 1:00 PM
> *To:* ironpython-users at python.org
> *Subject:* [Ironpython-users] DynamicObjects.TryConvert not called in
> IronPython?****
>
> ** **
>
> Hi,****
>
> ** **
>
> I am doing the similar thing as in "
> http://blogs.msdn.com/b/csharpfaq/archive/2009/10/19/dynamic-in-c-4-0-creating-wrappers-with-dynamicobject.aspx"
> to first convert any member into an object and then expect the
> object.TryConvert to handle the final convert. However, what is working in
> C# as double a = obj.M1.M2.M3 (return instance of Type C3, which has the
> TryConvert to convert it to double type) doesn't work in IronPython. The
> last step of converting instance of C3 to double in C3.TryConvert never
> happens.  I am currently using IronPython 2.7.0.40. Is this a known issue
> that has been addressed in 2.7.1 Beta?****
>
> ** **
>
> Thanks****
>
> -Patrick****
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20110624/7d5b512b/attachment-0001.html>


More information about the Ironpython-users mailing list