Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

[Python] Why is my syntax invalid?

  1. Mar 15, 2015 #1
    Code (Python):
    global m_mu = 106.0
    global M_Z = 91200.0
    global a = 1.0/128.0
    global theta_w = asin(sqrt(0.23152))

    global g_e = sqrt(4*pi*a)
    global g_Z = g_e/(cos(theta_w)*sin(theta_w))
    I have written this code in Python 2.7 using Enthought Canopy, and each line throws up a syntax error, but I have no idea why. Also, the values assigned to m_mu and M_Z used to be <<1 until I changed the units to make the numbers bigger, but when Enthought traces the line of code containing the syntax error, it gives me the old tiny value even though I had saved my changes. Does anyone know what is going on?

    PS - I know global variables aren't entirely encouraged, but it seems to be the best solution for what I'm trying to do. Perhaps I'll find another way, but that's for a different discussion.
  2. jcsd
  3. Mar 15, 2015 #2


    User Avatar
    Science Advisor

    I think your problem is the syntax of the global keyword in Python. For whatever reason, the statement:

    global x = 2

    is not valid syntax. You need to specify it as:

    global x
    x = 2

    This should fix your problem.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook