Does anyone have insight on why this happens?
My class looks like this and works:
class Breakfast:
food_types = ["Spam", "Ham", "Eggs"]
food = {
f: 1 for f in food_types
}
However, when I extend with like this:
class Breakfast:
food_types = ["Spam", "Ham", "Eggs"]
dislike = ["Spam"] # new
food = {
f: 1 for f in food_types
if f not in dislike # new
}
I get an error
NameError: name 'dislike' is not defined
Is the if-clause evaluated in a different scope or something like that?
Please don't suggest alternative ways to implement this, I am just trying to find out why this happens.