1 Replies - 521 Views - Last Post: 20 November 2013 - 08:55 AM Rate Topic: -----

#1 1/4_life_crisis   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-November 13

First post. I think it's about referencing to another class

Posted 19 November 2013 - 08:29 PM

http://www.codeskulp...EGfIONqR4S_1.py

My problem is: If you run this code in the above link,
type(c1)
(check line 67) is string rather than a a reference to the Card class (console guidline in line102)

My question is: I don't see a path of logic/don't know python well enough to make type(c1) reference Card without changing Deck format (the way its printing at the moment is how it needs to stay)

My thinking is as follows.

line 66 turns test_deck into a deck of cards in the form of a string "CA C2 C3..." - I need to change this somehow without changing this print (why? how?)

line 67 - I grab the first part of the deck alright. but instead of it being a reference to the Card Function,its a plain ole string.

...so: I need to change Deck from being a list of strings to a list of references to Card class.

problem is, I have no idea if this is correct, and if it is, how to go about it.

And I look forward to being part of this community.

Is This A Good Question/Topic? 0
  • +

Replies To: First post. I think it's about referencing to another class

#2 Rubiks14   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-November 13

Re: First post. I think it's about referencing to another class

Posted 20 November 2013 - 08:55 AM

When you're adding your cards to the deck you're not adding them as a card. you're just adding them as a string. Use this in place of your current code to add cards:

self.Deck.append(Card(i, r)


Not sure how to edit previous post but once you've edited the code for creating your cards you also need to edit your __str__ function under deck to look like this:

stri += s.__str__()

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1