Open s2t2 opened 4 years ago
meta = [{'properties': {'sheetId': 0, 'title': 'example-project', 'index': 0, 'sheetType': 'GRID', 'gridProperties': {'rowCount': 9, 'columnCount': 16}}, 'basicFilter': {'range': {'startRowIndex': 2, 'endRowIndex': 7, 'startColumnIndex': 0, 'endColumnIndex': 16}}}]
meta["sheets"]["basicFilter"]
"TypeError: list indices must be integers or slices, not str"
meta["sheets"][0]["basicFilter"]
setup code:
x = None
x["message"] #> TypeError: ______ object is not subscriptable
x[0] #> TypeError: ______ object is not subscriptable
stack trace:
File "/Users/mjr/projects/s2t2/tweet-analysis-py/app/retweet_graphs_v2/k_days_grapher.py", line 18
def get_daily_periods(start_date=START_DATE, k_days=K_DAYS, n_periods=N_PERIODS)
^
SyntaxError: invalid syntax
Reason: forgot a colon (can happen during function definition, for loop, if statement, etc.)
Can you spot the solution for this SyntaxError?
print(logstamp(), "|", fmt_n(self.counter), "|", fmt_n(edge_count) "EDGES")
^
SyntaxError: invalid syntax
Your answer here:
The interpreter says there's an error with code ABC on line X. You update the code its talking about. Then you run the script but it gives the same error message (reflecting the original code, not the updated code.
Lesson: remember to save your .py file before executing it 😸
The given code:
# web_app/routes/home_routes.py
from flask import Blueprint, render_template
home_routes = Blueprint("home_routes", __name__)
@home_routes.route("/")
def index():
print("VISITED THE HOME PAGE")
return render_template("home.html")
@home_routes.route("/about")
def about():
print("VISITED THE ABOUT PAGE")
return render_template("about.html")
@home_routes.route("/register")
def register():
print("VISITED THE REGISTRATION PAGE")
return render_template("register.html")
@home_routes.route("/topics")
def register():
print("VISITED THE TOPICS PAGE")
return render_template("topics.html", event_name="impeachment")
... produces the following Flask error:
AssertionError: View function mapping is overwriting an existing endpoint function: home_routes.register
Can you fix?
Answer:
There are two "register" functions. Need to rename the last one.
Error:
IndentationError: unindent does not match any outer indentation level
Cause: look at the beginning of the line it's talking about. And indent it properly.
Some students were asking for a list of common errors, like what do I do when I see "TypeError: list indices must be integers or slices, not str"