Why do I get the syntax error SyntaxError: invalid syntax in a line with perfectly valid syntax?
When an error is reported on a line that appears correct, try removing (or commenting out) the line where the error appears to be. If the error moves to the next line, there are two possibilities:
- Either both lines have a problem (and the second may have been hidden by the first); or
- The previous line has a problem which is being carried forward.
For example, code like the following, saved as twisty_passages.py
:
xyzzy = (1 +
plugh = 7
will produce an error on line 2, even though the problem is clearly caused by line 1: File "twisty_passages.py", line 2
plugh = 7
^
SyntaxError: invalid syntax
The code in the question has a similar problem: the code on the previous line has unbalanced parentheses. Annotated to make it clearer:# open parentheses: 1 2 3
# v v v
fi2=0.460*scipy.sqrt(1-(Tr-0.566)**2/(0.434**2)+0.494
# ^ ^
# close parentheses: 1 2
There isn't really a general solution for this - the code needs to be analyzed and understood, in order to determine how the parentheses should be altered. Code throwing syntax errors for no apparent reason
culprit: teams.append(list[x][BD.team]
-- missing parenthesis
def teams_and_games(list, player, idx):
teams = []
player_values = []
x = 0
y = 0
for rows in list:
if player == list[x][BD.player_id] and list[x][BD.player_id] not in teams:
teams.append(list[x][BD.team])
player_values.append([list[x][idx]])
x += 1
elif player == list[x][BD.player] and list[x][BD.player_id] in teams:
player_values[y].append(list[x][idx])
y += 1
return player_values, teams
Python Error SyntaxError: invalid syntax for no particular reason
You forgot a )
:
self.wih = (numpy.random.normal(0.0,pow(self.hnodes,- 0.5),
(self.hnodes,self.inodes)))
Related Topics
What's the Best Way to Store a Phone Number in Django Models
Binary Numpy Array to List of Integers
How to Increase Jupyter Notebook Memory Limit
In What Order Does Python Display Dictionary Keys
What Is the Relationship Between Google's App Engine Sdk and Cloud Sdk
Does Python Do Slice-By-Reference on Strings
Increment Numpy Array with Repeated Indices
How to Download a File from Google Drive Using Python and the Drive API V3
Make Part of a Matplotlib Title Bold and a Different Color
In Python, Is It Better to Use List Comprehensions or For-Each Loops
Pyspark Dataframes - Way to Enumerate Without Converting to Pandas
Matplotlib: How to Show a Figure That Has Been Closed
Is It Better to Use "Is" or "==" for Number Comparison in Python
Turning Off Logging in Selenium (From Python)
How to Explain the Reverse of a Sequence by Slice Notation A[::-1]