简体   繁体   中英

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

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 .

Assuming there wasn't a copy error and that is what your code actually looks like, you need to indent __init__() so that it is inside of the class definition:

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

edit: Now that you have included the full code, the issue is actually that you have nothing under your make_model() function definition. If that function is actually supposed to do nothing, add pass beneath the def line (indented one level). Otherwise, put some code there or remove the def line.

Shouldn't it be:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM