[Python] Why is my syntax invalid?

  • Context: Python 
  • Thread starter Thread starter sk1105
  • Start date Start date
  • Tags Tags
    Python
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 replies · 2K views
sk1105
Messages
88
Reaction score
12
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.
 
on Phys.org
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.