Thread: math module

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    1
    Rep Power
    0

    math module


    New to python,

    I understand that there should be a built in math module.

    If it is functional I should be able to;
    >>>pi
    3.1315......
    but I get;
    NameError: name 'pi' is not defined
    I can do;
    from math import pi
    but I should not have to do this.

    Anybody know what is going on?
    Thanks
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Just like the sys module the math module is always available for importing. To avoid name space pollution for one thing you still need to explicitly do the import.

    grimey
  4. #3
  5. A wanna-be guru of some sort
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2004
    Location
    Either online or offline
    Posts
    625
    Rep Power
    20
    Consider the following:

    Code:
     >>> import math
    >>> pi
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    NameError: name 'pi' is not defined
    >>> math.pi
    3.1415926535897931
    >>> from math import *
    >>> pi
    3.1415926535897931
    >>>

IMN logo majestic logo threadwatch logo seochat tools logo