Q:

Read .txt into Python Object and create a list

I am trying to make a card game using python. I have this text file below that is the Card ID, Card Name, Card Description, and Card Hit Point.
1, Medusa, Feel The Wraith, 98
2, Gigle , See Him See Him, 54
3, Brozi , Pinch an inch, 91

Below I have some python. I have this python class that is just a card. What I want to do is a have a Deck (list) of these Cards (Class Objects). Here is some code that I am trying to do that will read the text file and place them into objects and then into the list.
import sys
import os
class Card:
    def__init__(self, card_id, name, desc, hp):
        self.card_id = card_id
        self.name = name
        self.desc = desc
        self.hp = hp
        self.cards = []

deck = []

fh = open('dets.txt').readlines()
for line in fh:
    row = line.split(',')
    card_id, name, desc, hp = [i.strip() for i in row]
    card = deck.get(card_id, Card(card_id, name, desc, hp))
    deck[card_id] = card

Am I on the track? I am relatively new to Python. Thank you

A:

If you just want to put those card objects in a list, do this: 
deck = []
fh = open('dets.txt').readlines()
for line in fh:
    row = line.split(',')
    card_id, name, desc, hp = [i.strip() for i in row]
    card = Card(card_id, name, desc, hp)
    deck = deck + [ card ] 

Else, by looking at your code, I think you want to store them in a dictionary with card_id as key. To store them in a dictionary, 
deck = {} #dictionary
fh = open('dets.txt').readlines()
for line in fh:
    row = line.split(',')
    card_id, name, desc, hp = [i.strip() for i in row]
    card = Card(card_id, name, desc, hp)
    deck[card_id] = card #'card_id' is the 'key' and 'card' is 'value'

To print the name of cards in the dictionary, use for-loop,
for each_key in deck:
    print(each_key, " - ", deck[each_key].name )

This will give output:
1  -  Medusa
2  -  Gigle
3  -  Brozi

