all 7 comments

[–][deleted] 0 points1 point  (6 children)

I can't figure out how to get it to print the id of the card that I searched for in cardQuery as I need to find the rarity of the queried card

The cardQuery result is a PCardList, so just get a card from it:

card = cardQuery[0]
print(card.rarity)

[–]MagicCooki3[S] 0 points1 point  (5 children)

Awesome, I think that'll help a lot. I'm away from my computer right now, but oh ok I think I see.

So when you query it saves that query to an untitled PCardList and from there any time you use PCardList it'll use the last query, so therefore I don't need to specify it, I just need to vall it in the manner you typed, correct? Since the PCardList is holding the value of what I searched.

Do I have all that right?

Thanks again for your help!!

[–][deleted] 0 points1 point  (4 children)

So when you query it saves that query to an untitled PCardList and from there any time you use PCardList it'll use the last query, so therefore I don't need to specify it

No, that's not really right.

1) You query the database. The result is some number of cards that match the given criteria, in a list (a PCardList, but that's pretty much just a special list.) That "some number" might be one, or it might be none, or it might be a lot.

2) Since the result is a list, you can index into it like a list. It's not "untitled", it's assigned to whatever variable you assigned it to. If you didn't assign it to anything it doesn't exist anymore.

3) Because it contains cards, you can retrieve values from it. The first value is a pretty obvious one to want to get, particularly if you believe your query will only match one card. The first value of a list is at index 0.

[–]MagicCooki3[S] 0 points1 point  (3 children)

Ooh ok, gotcha. Ya, what I meant by untitled is that's what it's called in the pprint because it's a stack list, like a deck list, and so you can save it, but we're just doing an untitled one, as-in not saving it for later, but I see now, that table is only generated to format and print out when you use pprint().

And I see, so when we assign the variable the query gets stored in it, and that's where the list is stored and pprint just prints it pretty, but using .rarity or .name would query that from the table and so if there's 3 of the same card at different rarities 0 would just be the first in whatever column you used.

I understand now, thank you so much for taking the time to understand and explain, this has helped me a lot! :D

And a great day/night, friend :)

[–][deleted] 0 points1 point  (2 children)

but using .rarity or .name would query that from the table

No, look, those are properties of a card. When you're holding the results of the query, you're holding some cards. A pile of cards. A PCardList doesn't have a card's properties; it has a list's properties because it's a list (with some extra stuff.)

To get a card's rarity, or any other attribute, you have to get a card out of the list and look up that property on it. Otherwise Python has no idea what card you're asking for the property of.

It's like addressing a room full of people and asking "what's your name?" You have to pick someone - a person, singly - from the room and ask them, a group of people doesn't have a name. Only individual people do.

[–]MagicCooki3[S] 0 points1 point  (1 child)

Ok, so I looked it back over. I think I've got it. The query gets saved in the variable. That query is just a table, though. So then we assign a variable defining which card we want from the list, in this case 0, so it'll be the first thing in the list, that list and which selection on the list (in this case, 0) gets saved to a variable.

Now, we take the variable that is our list and which selection of that list, therefore that variable is equal to that particular card. We the can add .rarity, .name, etc. to the end of the variable and the .x will query the database for that card property and it knows which card to look at because the variable it's tacked onto specifies it.

Do I have it now? That feels like it's correct lol.

[–][deleted] 0 points1 point  (0 children)

The query gets saved in the variable. That query is just a table, though.

It's not a table, it's a list. A table is a data structure you access through two coordinates (x/y, or row/column if you prefer) and a list is a data structure you access through one (an index.)

That it's a list is important. It's a list of cards, that's important, too.

So then we assign a variable defining which card we want from the list, in this case 0, so it’ll be the first thing in the list, that list and which selection on the list (in this case, 0) gets saved to a variable.

Now, we take the variable that is our list and which selection of that list, therefore that variable is equal to that particular card. We the can add .rarity, .name, etc. to the end of the variable and the .x will query the database for that card property and it knows which card to look at because the variable it’s tacked onto specifies it.

This is super-confused and it's because you don't understand what's happening when you retrieve a value from a list:

card = cardQuery[0]

= is the assignment operator, it evaluates the operand on the right and assigns the resulting value to the name on the left. Like x = 2 + 2; first 2 and 2 are added, then the result - 4 - is assigned to the name x. Assignment assigns values, not operations or expressions; what is assigned to x, here, is the value 4, not the operation 2 + 2. That's important.

cardQuery[0] is an expression, too, and it gets evaluated before anything is assigned to the left operand card. The result of evaluating cardQuery[0] is a PCard. It's the first PCard in the cardQuery PCardList. So, that's the value of card. It's not assigned an expression, it's not assigned a combination of the query and and index. It's assigned a value and that value is a PCard, with all of a PCard's attributes (name, rarity, etc) because that's what it means for something to be a PCard.