无论我做什么,我都会收到缩进错误,即使没有缩进
I keep getting an indent error no matter what I do, even when there is no indentation
无论我做什么,我都想不通。无论我如何处理间距,我总是收到意外的缩进错误。
我花了两天时间尝试自己修复它并找到可以解释发生了什么的人。我附上了我的 CS50 IDE 的屏幕截图,因为我觉得它最能说明我遇到的错误。
@app.route("/sell", methods=["GET", "POST"])
@login_required
def sell():
if request.method == "POST":
quote = lookup(request.form.get("symbol"))
if quote == None:
return apology ("invalid symbol", 400)
try:
shares = int(request.form.get("shares"))
except:
return apology("shares must be positive", 400)
您需要 'close' 带有 except
的 try
块,即:
try:
shares = (int(request.form.get("shares"))
except Exception as err:
print(err)
或跳过 try
,当您知道预期的错误类型时使用 try-except,即:
shares = (int(request.form.get("shares"))
有关 try-except 个块的更多信息是 here。
所以关于缩进的错误具有误导性。我也去过:(
无论我做什么,我都想不通。无论我如何处理间距,我总是收到意外的缩进错误。
我花了两天时间尝试自己修复它并找到可以解释发生了什么的人。我附上了我的 CS50 IDE 的屏幕截图,因为我觉得它最能说明我遇到的错误。
@app.route("/sell", methods=["GET", "POST"])
@login_required
def sell():
if request.method == "POST":
quote = lookup(request.form.get("symbol"))
if quote == None:
return apology ("invalid symbol", 400)
try:
shares = int(request.form.get("shares"))
except:
return apology("shares must be positive", 400)
您需要 'close' 带有 except
的 try
块,即:
try:
shares = (int(request.form.get("shares"))
except Exception as err:
print(err)
或跳过 try
,当您知道预期的错误类型时使用 try-except,即:
shares = (int(request.form.get("shares"))
有关 try-except 个块的更多信息是 here。
所以关于缩进的错误具有误导性。我也去过:(