How do I define a global constant...

Discussion in 'Python' started by SpreadTooThin, Sep 20, 2006.

  1. 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...
    SpreadTooThin, Sep 20, 2006
    #1
    1. Advertising

  2. SpreadTooThin

    John Machin Guest

    SpreadTooThin wrote:
    > 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
    John Machin, Sep 20, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christopher M. Lusardi
    Replies:
    1
    Views:
    4,082
  2. Martin Magnusson
    Replies:
    2
    Views:
    502
    John Harrison
    Oct 8, 2004
  3. Tor Erik Soenvisen
    Replies:
    14
    Views:
    556
    Tim Roberts
    Nov 23, 2006
  4. Replies:
    4
    Views:
    337
    Keith Thompson
    Dec 14, 2006
  5. eiji
    Replies:
    5
    Views:
    466
    Rolf Magnus
    Dec 6, 2005
Loading...

Share This Page