How do I define a global constant...

S

SpreadTooThin

How do I define a constant that I can use in my script...
For example lets say I have a file called constants.py and in there I
have PI = 3.14

in my test script I do:

from constants import *

How do I access PI later on?


Pardon my newbie questions...
 
J

John Machin

SpreadTooThin said:
How do I define a constant that I can use in my script...
For example lets say I have a file called constants.py and in there I
have PI = 3.14

in my test script I do:

from constants import *

How do I access PI later on?

Like this:

inaccurate_estimate_of_area = PI * radius ** 2 # :)

You may wish to have a look at the built-in math module:

from math import *
much_better_area = pi * radius ** 2

HTH,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top