Encountered a python error today:
File "main.py", line 107
if __name__ == "__main__"
^
SyntaxError: invalid syntax
After a search, the sayings on the Internet are basically missing a space if __name__
after if
.
But I have spaces here, and manually deleting the spaces and reinserting the spaces will not work.
Finally, I checked for a long time, because there are many commented codes in the middle, just delete those codes. Later, for the first time, I found that it was because there was a blank line in the middle of a certain function, just delete the blank line. Presumably the previous redundant code may have also introduced blank lines.
In short the solution:
- Check if there is a missing space
if __name__
afterif
. - Check function for extra blank lines
- Check the commented redundant code, deleting it may have unexpected effects.