[Tutor] Scientific Notation + 18 Digit Pecision

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Dec 2 00:43:04 CET 2005


> Methods for turning on true division?
>
> A. Install the new Python, when it is available.
>
> When will this be available?

Hi Hubert,

Not certain.  It's not clear if this will be adopted as the default in the
immediate future; you might not want to wait for this.



> B.  from__future__import division
>
> This will work properly in an IDLE Python Shell, if I type it in, but
> not when it is present in .py modules.  I see that it was read from the
> .py file by the python shell, but the behaviour in the shell still is
> not changed from integer division to normal division. (I put the
> statement at the beginning of my .py modules.)

That directive only affects its enclosing module --- it doesn't affect
things globally.



> C. -Qnew
>
> I did not understand how to get and install Qnew, so I searched on the
> information below, and got a lot of results (1100), that confused me
> further.

I'm not on Windows, so I can't point out exactly what you'd need to
change to make IDLE and Python use the -Qnew argument flag.




> This approach might be the best, but before I consider it, I must get
> the two affected fuunctions working. I saved the function modules that
> you refactored for me, into separate files, but should probably put them
> all into one file later.
>
> 1. Extract Equation
> 2. EvaluateEquation
> 3. PrintEquationAndValue
> 4. DisplayPyFile
> and my
> 5. Calling Program Module
>
> When I ran the caling module, (and got the indentation right in the
> function modues) all modules appeared to work except for the
> PrintEquationAnd Value Function which gives a syntax error for "if
> value:" with an arrow pointing to value.

Next time, can you show us the exact error message?  Please give verbatim
error messages: they often help us figure out what exactly Python is
having an issue with.


> ############################################
> def PrintEquationAndValue(equation, value):
>  """Prints out the equation and its value."""
> if value:
>       name, assignment, comment = equation
>       print "%10s = %18.15e (%s)\t[%s]" % (name, value, assignment, comment)
> else:
>      print "%s not defined. %s" % (name, assignment)
> ############################################

The code you've sent us implies that the function body hasn't been
indented properly.  Can you check this?

I see that you're bouncing between indenting a function body with one,
two, or four spaces.  I'd recommend to stick with four, for consistency's
sake.


Good luck!



More information about the Tutor mailing list