Resolved: Unresolved reference in class with “self” keyword

Question:

I’m new at Python so I’m trying to create a class with some attributes inside of it. However, Pycharm gave me an Unresolved reference with the self usage. Here is my code:
from turtle import Turtle


class Pad:
    def __init__(self, is_player):
        self.is_player = is_player

    pad_body = Turtle()
    pad_body.penup()
    pad_body.shape("square")
    pad_body.shapesize(4, 1, 0)
    pad_body.color("white")

    if self.is_player:  # this is the place I get the error
        pad_body.setposition(-480, 0)
    else:
        pad_body.setposition(480, 0)
I’m not sure what am I missing in here. Why my self keyword doesn’t work properly?

Answer:

This worked for me. (Proper Indentation)
from turtle import Turtle

class Pad:
    def __init__(self, is_player):
        self.is_player = is_player

        pad_body = Turtle()
        pad_body.penup()
        pad_body.shape("square")
        pad_body.shapesize(4, 1, 0)
        pad_body.color("white")

        if self.is_player:  # this is the place I get the error
            pad_body.setposition(-480, 0)
        else:
            pad_body.setposition(480, 0)

If you have better answer, please add a comment about this, thank you!

If you like this answer, you can give me a coffee by <a href=”https://violencegloss.com/mkw7pgdwwr?key=2a96ade6f3760c7e63343a320febb78e”>click here</a>

Source: Stackoverflow.com