[英]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):
您可以:
擺脫那條線
在該函數的主體中編寫一些縮進代碼
縮進整個類定義,以便在函數中定義類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.