Question

I've read around enough to see that getcontext().prec is how to set the precision in a normal python file.

getcontext().prec = 100;
for i in range(1, 100):
    print 1.0 / i;

But when I execute this in IronPython, I get:

NameError: global name 'getcontext' is not defined

Is there an alternative way to change this, or does IronPython not get this luxury?

Here's my version info for VS and IronPython:

Microsoft Visual Studio 2010
Version 10.0.30319.1 RTMRel
Microsoft .NET Framework
Version 4.0.30319 RTMRel

IronPython Tools for Visual Studio   1.0
IronPython Tools for Visual Studio provides intellisense, project support, project and item templates, as well as a REPL window for IronPython development.

EDIT: Stupid me, I discovered the answer right after posting this (still learning some of the basics of python). I'm not going to answer this, but I'll pick the first person who has the right answer.

Was it helpful?

Solution

getcontext() would appear to be a function defined in the decimal module. Assuming you're going to be using the decimal module for math then you can just do:

from decimal import getcontext getcontext().prec = 10

That works for me on both IronPython 2.6 and 2.7B1.

But if you were going out of your way to use the .NET decimal class (via from System import Decimal) this would have no effect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top