When I run this code i get an error that says. Traceback (most recent call last): File "C:\Users\ept20\OneDrive\Desktop\student_file1.py", line 49, in stu_info.add_students(name, number, email) AttributeError: 'Studentinfo' object has no attribute 'add_students'       import pathlib class Studentinfo: def __init__(self): self.student_list = [] def save_students(self): """Saving the information to the record file""" record_file = pathlib.Path("c://users//ept20//onedrive//Desktop//student_file.txt") with record_file.open(mode='a', encoding='utf-8') as file: for info in self.student_list: name, number, email = info file.write(f'{name},{number},{email}\n') def add_students(self,name,number,email): """Add a student to the student list""" student_info = (name, number, email) self.student_list.append(student_info) class Student: def __init__(self, name, number, email): self.name = name self.number = number self.email = email print(f'A new student object: {self.name} is created') def read_file(): """This method loads saved student info from the record file""" record_file = pathlib.Path("c://users//ept20//OneDrive//Desktop//student_file.txt") if record_file.exists(): print('Saved students record:') with record_file.open(mode='r') as file: for stu_list in file.readlines(): print(stu_list ,end='') else: print('No saved student record') # Load existing student records stu_info = Studentinfo() while True: name = input("Please enter students name Press 0 to quit: ") if name == '0': break number = input("Please enter the students number: ") email = input("Please enter the students email: ") stu_info.add_students(name, number, email) #After add student information, save the student list to disk stu_info.save_students() read_file()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

When I run this code i get an error that says.

Traceback (most recent call last):
File "C:\Users\ept20\OneDrive\Desktop\student_file1.py", line 49, in <module>
stu_info.add_students(name, number, email)
AttributeError: 'Studentinfo' object has no attribute 'add_students'

 

 

 

import pathlib

class Studentinfo:
def __init__(self):
self.student_list = []

def save_students(self):
"""Saving the information to the record file"""
record_file = pathlib.Path("c://users//ept20//onedrive//Desktop//student_file.txt")
with record_file.open(mode='a', encoding='utf-8') as file:
for info in self.student_list:
name, number, email = info
file.write(f'{name},{number},{email}\n')

def add_students(self,name,number,email):
"""Add a student to the student list"""
student_info = (name, number, email)
self.student_list.append(student_info)

class Student:
def __init__(self, name, number, email):
self.name = name
self.number = number
self.email = email
print(f'A new student object: {self.name} is created')

def read_file():
"""This method loads saved student info from the record file"""
record_file = pathlib.Path("c://users//ept20//OneDrive//Desktop//student_file.txt")
if record_file.exists():
print('Saved students record:')
with record_file.open(mode='r') as file:
for stu_list in file.readlines():
print(stu_list ,end='')

else:
print('No saved student record')

# Load existing student records

stu_info = Studentinfo()

while True:
name = input("Please enter students name Press 0 to quit: ")
if name == '0':
break
number = input("Please enter the students number: ")
email = input("Please enter the students email: ")
stu_info.add_students(name, number, email)

#After add student information, save the student list to disk

stu_info.save_students()


read_file() 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Files and Directory
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education