Error 'math.Pi()' in rhino python

Hi there.
i try to run rhinopython code of below lines.
‘’’
import math
import rhinoscriptsyntax as rs
pi = math.Pi()
‘’’
in this case i met an error message like “‘module’ object has no attribute 'Pi”.
I can’t understand this case. What’s the problem ?
Thanks a lot^^

Try using just

math.pi

And also: if you want to have a pi as a math.pi, you can import it like that:

from math import pi

1 Like

Thank you for your reply. But it couldn’t run. This code lines come from Rhino’s sample file at RhinoPython book. Full codes are here.
‘’’
import math
import rhinoscriptsyntax as rs
pi = math.Pi()
dblTwistAngle = 0.0

rs.EnableRedraw(False)
for z in rs.frange(0.0, 5.0, 0.5):
dblTwistAngle = dblTwistAngle + (pi/30)

for a in rs.frange(0.0, 2*pi, (pi/15)):
    x = 5 * math.sin(a + dblTwistAngle)
    y = 5 * math.cos(a + dblTwistAngle)
    rs.AddSphere([x,y,z], 0.5)

rs.EnableRedraw(True)
‘’’
I don’t know why math.py() did’nt run in this case?

math.pi is lowercase, you’re calling it with a capital P in line 3. It’s also not a function, so you don’t need the round brackets at the end. See:

https://docs.python.org/2.7/library/math.html

1 Like

Yes, this comes from the Rhino.Python 101 pages, section 5.4. The error “math.Pi()” exists in the Rhino 7 and WIP online versions (and probably earlier ones) and in the downloadable PDF @pascal.

Thank you for your help. I solved it using another code line like this.
" pi = math.pi " that Anders and Jeremy’s comment talked to me.
Have a happy python at Rhino all of you^^