I'm trying to code a card trick using a combination of Python and Powershell (I'm well aware that it could be done with either Python or Powershell, but I want to practice with both anyway). When doing the Python part of the trick, I'm running into an error about NoneType
not having an attribute __getitem__
. I think I found an answer for the question at this question here TypeError: 'NoneType' object has no attribute '__getitem__' but I did not really understand what the answers meant (I'm still a beginner at this stuff). Also, I found another question where someone was attempting to do what I was doing (How to assign each element of a list to a separate variable?), but everyone at that post merely said that what he was doing was unnecessary instead of giving an answer. Essentially, I want to do what he was trying, except for only the first variable.
Here is my code:
from random import shuffle
TheList = ["Ace of Spades", "Three of Hearts", "Five of Diamonds", "Seven of Clubs", "Nine of Spades", "Jack of Hearts", "King of Diamonds", "Two of Clubs", \
"Four of Spades", "Six of Hearts", "Eight of Diamonds", "Ten of Clubs"]
TheShownCards = shuffle(TheList)
TheChosenCard = TheShownCards[0]
print TheShownCards
print TheChosenCard
Here is the error I'm getting:
TypeError: 'NoneType' object has no attribute '__getitem__'
The print
commands at the end are just for debugging, and I will remove them once I finish the script. Essentially, I'm trying to get the first item of list TheShownCards
to be saved as the variable TheChosenCard
. I know that this might be pointless and unnecessary (I read that other post where people told him not to), but my idea here is not just to get the info to complete the program, but also to learn how to do it the way requested. If it does prove to be too much of a hassle, I'll probably scrap the variable, but any help on the matter would be appreciated.