我不明白为什么在尝试创建类“ Deck”的实例时,PyCharm返回“ Deck不可调用”的错误。
Main.py
if __name__ == '__main__':
while play_again is True:
player_count: int = int(input("Enter number of players: "))
print(player_count)
game_deck: Deck = Deck("game") #error on this line
shuffle(game_deck)
burn_deck = Deck
Deck.py
class Deck:
card_sequence: Card = []
deck_type = ""
def __init__(self, deck_type):
card_suits = ['Clubs', 'Diamonds', 'Hearts', 'Spades']
card_ranks = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', 'Jack', 'Queen', 'King']
self.deck_type = deck_type
if self.deck_type == "player":
for i in range(2):
self.card_sequence = [random.random() for _ in range(2)]
elif self.deck_type == "game":
for i in card_suits:
for j in card_ranks:
new_card = Card(i, j)
self.card_sequence.push(new_card)
for _ in self.card_sequence:
self.card_sequence.append(random.random())
elif self.deck_type == "burn":
self.size = 0
self.card_sequence = []
错误
Traceback (most recent call last):
File "C:/Users/Chris/PycharmProjects/BlackJack/Main.py", line 36, in <module>
game_deck: Deck = Deck("game")
TypeError: 'module' object is not callable
答案 0 :(得分:1)
您需要导入模块并创建一个对象,如下所示:
from Deck import Deck
deck = Deck()
或
import Deck
deck = Deck.Deck()