Hello Anvil Forums!
I am a novice Python user and am working my way through the tutorials. I was hoping to get a few pointers on the code used in Chapter 3 of the News Aggregator tutorial at: https://anvil.works/learn/tutorials/database-backed-apps/chapter-3
I think my issue is there is some short forms or alias being used and I am just not familiar enough to catch it. The code is from this part:
categories = [ (cat['name'], cat) for cat in app_tables.categories.search() ]
Later on it includes this bit of code as well:
self.category_box.items = categories
Working backwards from these two items I think I get the general idea. This bit of code
self.category_box.items = categories
is saying āhey buds, you are going to change the contents of the category box you made earlier and fill it up with the stuff found in the categories variableā.
For the next bit of code I get a bit of what it is saying but not sure how all of the areas were decided on. So for this bit
categories = [
(cat[ānameā], cat) for cat in app_tables.categories.search()
]
it is saying āhey buds, you are going to make a variable called categories and use stuff you find in the categories table. You are going to find a column called name in there and take stuff from thatā. I guess Iām getting confused on the ācat, cat, for catā part of this bit. When I type out the cat part it does give a quick access pop-up that says ācat ā ācategoriesā row, A row from the ācategoriesā table, View docsā¦ā but Iām not sure how it went from a table name ācategoriesā to having just ācatā. I donāt remember making an alias or shortcut for this. I tried changing the code to say ācategoriesā and it works as well and made a bit more sense. How do I end up going from ācategoriesā to just ācatā?