jeudi 20 avril 2017

Print a list from my class (python)

I have i class with information about customers. One of all the things is self.history were i save history for every customer in a list. Every customer is also in a dictonary outside the Class were I have saved the name as key, and other information as values. My question is how i print this list for every customer.

i have tryed:

class Customer:
    def __init__(self, name, car, reg):
        self.name = name
        self.car = car
        self.reg = reg
        self.history = []


def add_new_customer:
    account = dict()
    name = input("Name: ")
    car = input("Car: ")
    reg = input("Regnummber : ")
    account[name] = Customer(name, car, reg)


def print_all_accounts():
    for keys in account:
        print(keys.history)

the code is bigger and I do a lot of things like name.history.append() and so on (500 lines). But this is the thing who dosen't work.

i get in return

AttributeError: 'str' object has no attribute 'history'






Comments
0 Comments

0 commentaires:

Enregistrer un commentaire