Mark
Mark

Reputation: 511

SyntaxError: invalid syntax I have checked for mix of Tabs & Spaces

I have this code:

        for urls in new_keywords
            if urls not in old_keywords
                upload_keywords.append(urls)

And my error:

  File "controller.py", line 56
    for urls in new_keywords
                           ^
SyntaxError: invalid syntax

I had this error before and the issue was a mix of spaces and tabs as indent. I have checked this and with my editor I can see only dots (spaces) but it doesn't seem to work? any ideas?

Upvotes: 0

Views: 746

Answers (3)

Steven Rumbalski
Steven Rumbalski

Reputation: 45541

You are missing some colons

for urls in new_keywords: # <======== here
    if urls not in old_keywords: # <= and here
        upload_keywords.append(urls)

Upvotes: 3

sasha.sochka
sasha.sochka

Reputation: 14715

You missed a colon on each of the first 2 lines of your snippet.

Change

for urls in new_keywords
    if urls not in old_keywords

To

for urls in new_keywords:
    if urls not in old_keywords:

You should always put colons after for statements (as well as while, if and some other)

Upvotes: 3

carl-lopez
carl-lopez

Reputation: 582

You're missing a colon, it should be like:

for urls in new_keywords:
    if urls not in old_keywords:
        upload_keywords.append(urls)

That's why you get the invalid syntax error

Upvotes: 9

Related Questions