Продолжаю учиться на основе телефонной книги. Вопрос возник в записи значений в текстовой файл.
Создаю список с именем, фамилией, телефоном и записываю в файл. Как можно сделать так, чтобы следующий контакт( имя, фамилия, телефон) записывались в новой строке.
class PhoneBook:
def new_contact(self, name, surname, tel):
self.name = name
self. surname = surname
self.tel = tel
print 'Person:', name, surname
print'Telephone number: ', tel
def contact_write(self, contacts):
self.contacts = contacts
address_book = open('address_book.txt', 'a')
for item in contacts:
address_book.write('%s ' % item)
address_book.close()
print'Contact saved'
if __name__ == '__main__':
new_contact = PhoneBook()
while True:
name = str(input('Name: '))
surname = str(input('Surname: '))
tel = str(input('Telephone number: '))
contacts = [name, surname, tel]
new_contact.new_contact(name, surname, tel)
new_contact.contact_write(contacts)