Search code examples
pythonxcodeindentation

Python IndentationError: “expected an indented block” on Xcode


I've been getting this error on xcode and vi. Python says the line class LeastModel has an IndentationError: expected an indented block. I checked my preferences on Xcode to use 4 spaces for a tab and everywhere I've been using tab. Please help me!

def make_model(data,model):

class LeastModel():
    """
    linear system solved using linear least squares
    This class serves as an example that fulfills the model interface needed by the ransa function.
    """
    def __init__(self,input_columns,output_columns):
        self.input_columns = input_columns
        self.output_columns = output_columns
        #self.debug = debug

Solution

  • Your problem is that you have no indented code after the line:

    def make_model(data,model):
    

    You can either:

    1. Get rid of that line

    2. Write some indented code into the body of that function

    3. Indent your entire class definition so that you are defining the class LeastModel within the function.

    Judging by the fact that you called your function make_model and your class LeastModel, I think you somehow intended to put the class definition within the function. But this might be a mistake on your part- note that if you define it in a function, you won't be able to use the class outside of the function (unless you return the class itself from the function, with the line return LeastModel.