Problem with Syntax

Hello, when I compute the following function :
def LBTest(x):
globals()
T=x.shape[0];
temp=;
output=;
critical=;
for i in range(1,x.shape[0]):
temp+=(1/(T-i)np.power(x.autocorr(i),2)
output = [temp
T*(T+2)];
critical=[ss.chi2.isf(.05,x.shape[0])];
return (output, critical)

I got the following error message, and I do not understand why as it is in the variable declaration.
output = [tempT(T+2)];
^
SyntaxError: invalid syntax

Thanks !

Something to look into which errors like this, especially when the line reported seems correct is too look at lines before. In this case there’s a closing parenthesis missing on the line before.

One general note about your code: It is not necessary to have semi-colons at the end of lines in Python, and the usual coding style is to leave them out.

What are you trying to accomplish using the “globals()” line at the start of the function? As currently written it has no observable effect.

Thanks you very much i did not see the open paranthesis.
I put globals() because a friend told me that it may resolve my problem.
It work now I can apply the function to my dataframe

Thanks you very much i did not see the open paranthesis.

If you have an editor which will show you a parenthesis’ matching
character eg the opening parenthesis from standing at the closing
parenthesis, you can sometimes find these by typing what you think is an
“extra” closing parenthesis - if the editor finds an “open” for it then
there is your problem.

I put globals() because a friend told me that it may resolve my problem.

This feels like magical thinking. Did your friend explain why that
might help?

Syntax errors are inherently about text structure.

Calling globals() on its own changes nothing, because that is a function
call. It has no side effects, even in a running programme - it exists to
proovide certain information.

If your friend was talking about the “global” statement, that just marks
a name as coming from the global (file level) scope rather than being a
function local variable. Against, nothing to do with syntax.

It is usually useful to strip out as much as you can from your failing
code. By all means try the “globals()” thing, but when it doesn’t change
anything, remove it. That way there are fewer distractions in the code
from the problem you are trying to find.

Cheers,
Cameron Simpson cs@cskk.id.au

Thanks you very much for your explanation
Cheers,
Polo