[IronPython] Exceptions with double values

Pat29 parault2 at wanadoo.fr
Sat Oct 2 17:35:53 CEST 2004


After launched the IronPython interpreter, i tried these simple inputs:
>>> 1.5
or
>>> 1.5 + 2.5
Each time, an exception raised and i was disappointed.
On my home computer, it's the same thing with this C# code snippet:

string x = "1.5";
string y = 2.5";
Console.WriteLine("x + y = {0}", Convert.ToDouble(x) + Convert.ToDouble(y));

But the following code will work fine:

string x = "1,5";
string y = 2,5";
Console.WriteLine("x + y = {0}", Convert.ToDouble(x) + Convert.ToDouble(y));

Like all .NET assemblies, the IronPython interpreter will use the current Culture informations.
For some no English user like me, it's the reason that you get an exception with double values in the interpreter or in the b3/b5 modules when you try the parrotbench test.
But i wanted to do this benchmark and the idea was to change the Culture informations.

After to have modified the parrotrun.py file (renamed parrotrunUS.py) like this:

.........
.........
""" This provides a more convenient harness for running this
    benchmark and collecting separate timings for each component.
"""

from time import clock
import sys

#Begin new code
from System import Threading
from System import Globalization

Threading.Thread.CurrentThread.CurrentCulture = Globalization.CultureInfo.CreateSpecificCulture("en-US")
#End new code

t0 = clock()
import b0
import b1
.........
.........

The test had worked. You can do the same thing with the interpreter
>>>from System import Threading
>>>from System import Globalization
>>>Threading.Thread.CurrentThread.CurrentCulture = Globalization.CultureInfo.CreateSpecificCulture("en-US")
>>> 1.54 + 2.28
>>>3.82

This modification is only usefull for some people.
@+




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20041002/1094eb2b/attachment.html>


More information about the Ironpython-users mailing list