繁体   English   中英

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

[英]Python IndentationError: “expected an indented block” on Xcode

我一直在xcode和vi上收到此错误。 Python说线类LeastModel有一个IndentationError:期望是一个缩进的块。 我在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

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

def make_model(data,model):

您可以:

  1. 摆脱那条线

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

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

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

假设没有复制错误,而这正是您的代码的实际外观,则需要缩进__init__() ,使其位于类定义中:

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

编辑:现在您已经包含了完整的代码,问题实际上是在make_model()函数定义下您什么都没有。 如果实际上该功能不起作用,请在def线(缩进一级)下方添加pass 否则,在此处放置一些代码或删除def行。

不应该是:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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