I'm a little bit stuck with checking if user's input is correct. I don't know how to properly call "name" and other fields inside of lookup function to check them. I've tried different combinations of parenthesis (e.g., ["name"], (name), (["name])), but none of them seem to work.

Any suggestions about this problem?

Here is my code:

if request.method == "POST":  
    quote = request.form.get("symbol")  
    result = lookup(quote)  
    if not result("name"):  
        return apology*=("invalid symbol", 403)  
    return render_template("quoted.html", result=result)  
    return render_template("quote.html")    

1 Answer 1


If lookup() doesn't find the requested symbol, it will return None. That is not explicitly stated in the spec, but that is what the try/except block does in the function.

None is not subscriptable, so result["name"] will give an error in the case that lookup hasn't found a stock.

Since None is falsey, if not result: will evaluate to true if lookup returned None.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .