Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 why my method doesn't find my List in the same class?
#1
hello everybody,

I am begginner in python. I wrote the code under and I don't understand why I have the error you can find under

from random import *

class CardGame (object):
    Color = ["heart", "diamond", "club", "spade"]
    Value = [2, 3, 4, 5, 6, 7, 8, 9, 10, "valet", "queen", "king", "ace"]

    def __init__(self):
        self.cards = []
        for A in Value :
            for B in Color :
                self.cards.append((A, B))

    def CardName (self, Card):
        return "{0} of {1}".format(Value[Card[0]], Color[Card[1]])

    def ShuffleGame (self):
        return shuffle(self.cards)

    def TakeCard (self):
        return self.cards.pop()
Error:
Traceback (most recent call last): File "/Users/nic/Desktop/python/Card_Game_2.py", line 22, in <module> Game = CardGame() File "/Users/nic/Desktop/python/Card_Game_2.py", line 9, in __init__ for A in Value : NameError: name 'Value' is not defined
Thanks for your help
Quote
#2
Value is a class attribute. You need to access that with self, just as you do with the instance attribute cards.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#3
(Jan-31-2019, 05:15 PM)ichabod801 Wrote: Value is a class attribute. You need to access that with self, just as you do with the instance attribute cards.

thanks you so much, you save my brain and probably my laptop as well :)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to find the first and last of one of several characters in a list of strings? tadsss 1 29 25 minutes ago
Last Post: buran
  Find index value in List Martin2998 3 206 May-12-2020, 02:17 PM
Last Post: deanhystad
  calling on a method from one class into another class which is not a child NABA 5 168 Apr-29-2020, 07:49 PM
Last Post: deanhystad
  TypeError: type str doesn't define __round__ method emmapaw24 7 1,153 Feb-03-2020, 08:38 PM
Last Post: snippsat
  How to find something in a list using its index rix 1 227 Dec-20-2019, 04:12 PM
Last Post: stullis
  threading for method outside class anna 0 165 Nov-17-2019, 07:05 AM
Last Post: anna
  how can I changing a base class method voidptr 2 216 Nov-10-2019, 10:53 PM
Last Post: voidptr
  How to Call a method of class having no argument dataplumber 7 724 Oct-31-2019, 01:52 PM
Last Post: dataplumber
  print all method and property of list object engmoh 4 468 Oct-26-2019, 05:33 PM
Last Post: engmoh
  Call method from another method within a class anteboy65 3 441 Sep-11-2019, 08:40 PM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)