# [Tutor] Scientific Notation + 18 Digit Precision

Hubert Fitch photonquark at comcast.net
Sun Nov 27 13:27:07 CET 2005

```Thanks to all of you (Alan, Chris, Kent) for your responses!

Before I try to follow up on these suggestions, it might be good to examine the display function module, and provide a few lines from a .py module that needs display.

Typical lines in a defintion module, that need a formatted display :
(All referenced symbols in this module are previously defined in another module)

# -------------------------------------------------------------------------------------------------------------------
#       VARIABLE  NAME,     DATA ,   ASSIGNMENT FORMULA,      COMMENT
# -------------------------------------------------------------------------------------------------------------------
#
#       INDUCTANCE
L0 = pi*mu0*r0    #  Classical Inductance
#       CAPACITANCE
c0 = 4*pi*ep0*r0  # Classical Cpacitance

n = 2    # Quantum Number
r3 = (r0*(n/a)**2    ) # Bohr radius

#       ORBIT VELOCITY
v3 = Q0**2/(2*h*ep0*n) # Bohr Orbit Velocity
v = a*C/n

#        Bohr Orbit Velocity
v3 = v                  #  Bohr Orbit Velocity
g3 = (1-v3**2/C**2)**-0.5 #  Gamma

#       FREQUENCY
f3  = g3*m0*v3**2/h  #  Bohr Orbit deBroglie frequency
---------------------------------------------------------------------------------------------

Most of the formatted results are already provided in the correct form.
What should be changed in this display function module?
-----------------------------------------------------------------------------------------------------------------
Display Function Module:
(Written by Dr. Steve Spiklemire, Physics Dept Head Universtiy of indianapolis)
-----------------------------------------------------------------------------------------------------------------

def DisplayPyFile(fname, context=None):

if context is None:
context = globals()
f = open(fname)
f.close()

for line in lines:
line = line.strip()
if not line:
continue
leftAndRight = line.split('#',2)
comment = ''
if len(leftAndRight)>1:
comment = leftAndRight[1]

assignment = leftAndRight[0]
leftAndRight = assignment.split('=')
if len(leftAndRight) == 2:
name = leftAndRight[0].strip()
exec(assignment, context)
if context.get(name,None) is not None:
value = context.get(name,'???')
print "%10s  =  %18.15e (%s)\t[%s]" % (name, value, assignment, comment)
else:
print "%s not defined. %s" % (name, assignment)
else:
print line
-----------------------------------------------------------------------------------------------------------------------------

Hubert

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20051127/52fa26a6/attachment.htm
```