Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unexpected indent / invalid syntax
#7
You have to learn to read the tea leaves in the Traceback Error or Syntax Error. The error is usually in the line number specified in the Error message. Sometimes the error is in the line before the line number specified, when something is missing.

Output:
File "temp.py", line 52 filename = self.log_path / 'comp{}'.format(url[p 1:]) ^ SyntaxError: invalid syntax
From looking at your code and similar lines, you probably want to move the pointer to after the '=' sign similar to other constructions in your code:
Try:
 filename = self.log_path / 'comp{}'.format(url[p + 1:])
The next error is:
Output:
File "temp.py", line 54 except KeyError ^ SyntaxError: invalid syntax
Try to figure this one out yourself. Look around at similar constructions to see what is different.


When you get to the syntax error at the bottom of the file, it gets a little tricky, because you first have to fix the error on the top line:
    f.write('{}\n'.format(td.text)
if__name__ == '__main__':
   GetCompletions('api.txt')
which looks like it occurs on the next line. The next line also has an error, which makes it a little tricky for a beginner. Clue to the last error: there is a missing 'space'.

Lewis
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00
Reply


Messages In This Thread
Unexpected indent / invalid syntax - by tjnichols - May-13-2018, 08:56 PM
RE: Unexpected indent / invalid syntax - by Larz60+ - May-14-2018, 02:26 AM
RE: Unexpected indent / invalid syntax - by nilamo - May-14-2018, 06:24 PM
RE: Unexpected indent / invalid syntax - by ljmetzger - May-14-2018, 07:24 PM
RE: Unexpected indent / invalid syntax - by Larz60+ - May-14-2018, 11:14 PM
RE: Unexpected indent / invalid syntax - by wavic - May-14-2018, 11:50 PM
RE: Unexpected indent / invalid syntax - by Larz60+ - May-15-2018, 12:25 AM
RE: Unexpected indent / invalid syntax - by nilamo - May-15-2018, 04:01 PM
RE: Unexpected indent / invalid syntax - by Larz60+ - May-15-2018, 09:25 PM
RE: Unexpected indent / invalid syntax - by nilamo - May-15-2018, 09:55 PM
RE: Unexpected indent / invalid syntax - by Larz60+ - May-16-2018, 01:06 AM
RE: Unexpected indent / invalid syntax - by wavic - May-16-2018, 02:23 PM
RE: Unexpected indent / invalid syntax - by Larz60+ - May-16-2018, 03:04 PM
RE: Unexpected indent / invalid syntax - by wavic - May-16-2018, 03:07 PM
RE: Unexpected indent / invalid syntax - by Larz60+ - May-16-2018, 03:13 PM
RE: Unexpected indent / invalid syntax - by wavic - May-16-2018, 03:26 PM
RE: Unexpected indent / invalid syntax - by Larz60+ - May-16-2018, 05:03 PM
RE: Unexpected indent / invalid syntax - by Larz60+ - May-16-2018, 05:37 PM
RE: Unexpected indent / invalid syntax - by wavic - May-16-2018, 05:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  IndentationError: unexpected indent in views.py ift38375 1 2,546 Dec-08-2019, 02:33 PM
Last Post: michael1789
  IndentationError: unexpected indent salahhadjar 2 4,427 Nov-04-2018, 06:10 PM
Last Post: salahhadjar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020