Nick
Nick

Reputation: 161

return outside function, or unexpected indent

I have this:

if colorkey is not None:
        if colorkey is -1:
         colorkey = image.get_at((0,0))
image.set_colorkey(colorkey, RLEACCEL)
return image, image.get_rect()

It tells me that "return" is outside the function.

When I change it to this:

if colorkey is not None:
        if colorkey is -1:
         colorkey = image.get_at((0,0))
image.set_colorkey(colorkey, RLEACCEL)
    return image, image.get_rect()

It just tells me that there is an unexpected indent. How do I get around this?

Upvotes: 1

Views: 7478

Answers (2)

pajton
pajton

Reputation: 16226

In python, scopes are defined by the same level of indentation instead of braces (i.e. {}) as in other languages.

If you write a function, you need to ensure that all function body is at the same level of indentation - be it the same amount of spaces or the same amount of tabs (mixing spaces and tabs can result in real mess).

In your case, the correct indentation would look similar to (I do not know exactly, because you didn't post the code for whole function):

def function():
<indent>if colorkey is not None:
<indent><indent>if colorkey is -1:
<indent><indent><indent>colorkey = image.get_at((0,0))
<indent>image.set_colorkey(colorkey, RLEACCEL)
<indent>return image, image.get_rect()

Upvotes: 4

Andrey Sboev
Andrey Sboev

Reputation: 7682

after if colorkey is not None: there are 2 indents, it needs only one

Upvotes: 0

Related Questions