Error Expected An Indented Block In My Docstring
Solution 1:
Just indent every line in your class (up to the line print("Category :....")
).
Python should know when the class starts and when it stops. And it knows that with indentation.
Solution 2:
def print_status(self):
print("Category :",self.name,"\n category type :"self.category_type,"\n Model :"self.model)
It seems you are missing a comma before self.Model in the above statement.
Solution 3:
A docstring, as its name suggests, is a string literal. Since it is not a comment, it follows the same indentation requirements as any other code in the body of the class (i.e. it must be indented).
Here's a related question with more detail: IndentationError from comment in python
Solution 4:
Answer :
classCategory:
"""
Creates category class, possible child class of products
Parameters
name : str, default blank
Desired name of category
category_type : str, default blank
type of category
model : int , default 0
model of category in years
"""#Declaring __init__()Functiondef__init__(self,name="",category_type="",model=0):
self.name = name
self.category_type = category_type
self.model = model
print (name,"Created!") # Run when init is finished.#Declaring print_status()Functiondefprint_status(self):
print("Category :",self.name,"\n category type :", self.category_type,"\n Model :", self.model)
Discussion:
The def
statements need to be indented relative to the class
statement, just as the body of the def
s are indented relative to the first line of the defs
.
Independently, your print
statement in the last line of your class contains syntax errors. I fixed them by inserting commas between arguments of print
. Now, while I can vouch that my changes make your class free of syntax errors, I can't guarantee that it prints what you want it to print. I suggest that you test that.
Post a Comment for "Error Expected An Indented Block In My Docstring"