Physical constants

Rares Vernica rvernica at gmail.com
Sat Nov 4 03:38:33 CET 2006


Hi,

I am not sure how the constants are implemented in math, but here is how 
I would do it. The main idea is to declare the constants as globals in 
some file.

Declare all the constants in a file:
const.py
---
pi = 3.14

Whenever you want to use pi from another file, just do:
somecode.py
---
from const import pi

a = 2 * pi

Regards,
Ray

Tommy Grav wrote:
> I have some code for doing orbital computations. The code is kind of
> extensive with many classes, each having several functions. In these
> functions I need to use constants (like the gravitational constant). 
> What is the best way of implementing a solution when constants are
> used in several different classes and functions? I do not want to 
> pass the constant down through the functions. I have thought of
> making a class of constants but I do not want to invoke an 
> instant in each function. How is the pi and e constants in math
> coded?
> 
> Tommy
> 
> tgrav at mac.com <mailto:tgrav at mac.com>
> 
> http://homepage.mac.com/tgrav/
> 
> 
> "Any intelligent fool can make things bigger, 
> more complex, and more violent. It takes a 
> touch of genious -- and a lot of courage -- 
> to move in the opposite direction"
>                          -- Albert Einstein
> 
> 




More information about the Python-list mailing list