0

I am trying to create a Blackjack project in Python.

I am trying to create my Card.py object into my Deck.py object, but using:

from Models import Card


class Deck:
    # Global Properties of Deck
    __cards = []

    def __init__(self):
        self.__set_deck()

    # Get Methods
    def get_cards(self):
        return self.__cards

    # Set Methods
    def __set_deck(self):
        test = Card("Three", "Clubs")
        self.__cards.append(test)


obj = Deck()

with:

class Card:
    # Global Properties of Card
    __rank = ''
    __suit = ''

    # Constructor
    def __init__(self, rank, suit):
        self.__set_rank(rank)
        self.__set_suit(suit)

    # Get Methods
    def get_rank(self):
        return self.__rank

    def get_suit(self):
        return self.__suit

    # Set Methods
    def __set_rank(self, rank):
        self.__rank = rank

    def __set_suit(self, suit):
        self.__suit = suit

gives me a TypeError: 'module' object is not callable where I am creating the Card object.

Any suggestions? I don't know where to start looking.

martineau
  • 119,623
  • 25
  • 170
  • 301
Steve
  • 97
  • 1
  • 10
  • 2
    Does this answer your question? [TypeError: 'module' object is not callable](https://stackoverflow.com/questions/4534438/typeerror-module-object-is-not-callable) – Brydenr Dec 31 '19 at 21:45
  • 2
    If your class is in a file called `Card.py`, then `Card` is a module, and the `Card` class is inside it. – khelwood Dec 31 '19 at 21:46
  • @khelwood I am not that proficient in python, but what does that mean? How can I create my Card class in my Deck class? Or am I approaching this incorrectly? – Steve Dec 31 '19 at 21:52

1 Answers1

2

Method 1

Here's how you would do it.

from Card import Card

Card()

The first Card represents the Card.py file while the second Card represents the Card class.

Method 2

You can also just import the Card file and call the card class from there on after such as so:

import Card

Card.Card()
SafeDev
  • 641
  • 4
  • 12
  • The specific solution to my issue is: from Models.Card import Card, this is because the Card module is inside a folder named Models – Steve Dec 31 '19 at 22:50