from courses.Attachment import Attachment class Course: id: None title: "" description: "" duration: 0 attachments: [] def __init__(self, course_id, title, description, attachments=None): self.id = course_id self.title = title self.description = description self.attachments = attachments if attachments else [] def add_attachment(self, attachment): self.attachments.append(attachment) def __repr__(self): return f"Course(id={self.id}, title={self.title}, description={self.description}, attachments={self.attachments})" # 使用示例 # 创建附件实例 attachment1 = Attachment(attachment_id=1, course_id=101, name='Lesson 1', url='http://example.com/lesson1.mp3') attachment2 = Attachment(attachment_id=2, course_id=101, name='Lesson 2', url='http://example.com/lesson2.mp3') # 创建课程实例,并添加附件 course = Course(course_id=101, title='Introduction to Python') course.add_attachment(attachment1) course.add_attachment(attachment2) print(course)