Physical constants
Steven D'Aprano
steve at REMOVE.THIS.cybersource.com.au
Sat Nov 4 00:49:21 EST 2006
Apologies for breaking threading, but my ISP seems to have eaten the
original post from Tommy. Hence I'm replying to a reply.
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?
If all your code is in the one file, then it couldn't be simpler. E.g.:
# orbital computations
# define some constants
G = 1.0 # gravity is strong in this universe...
# define some functions
def force_of_gravity(m1, m2, r):
return G*m1*m2/r**2
--
Steven.
More information about the Python-list
mailing list