Python IndentationError:Xcode 上“预期有缩进块”

sna*_*iii 1 python xcode indentation

我在 xcode 和 vi 上遇到了这个错误。Python 表示行类 LeastModel 有一个 IndentationError: Expected an indented block。我在 Xcode 上检查了我的首选项,以使用 4 个空格作为制表符,并且在我一直使用制表符的任何地方。请帮我!

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
Run Code Online (Sandbox Code Playgroud)

Dav*_*son 5

您的问题是该行后没有缩进代码:

def make_model(data,model):
Run Code Online (Sandbox Code Playgroud)

您可以:

  1. 摆脱那条线

  2. 将一些缩进代码写入该函数的主体中

  3. LeastModel缩进整个类定义,以便在函数中定义该类。

make_model从您调用函数和类的事实来看LeastModel,我认为您以某种方式打算将类定义放在函数中。但这可能是您的一个错误 - 请注意,如果您在函数中定义它,您将无法在函数外部使用该类(除非您使用return LeastModel.