[Tutor] Object oriented design

jamie hu jamiehu17 at yandex.com
Sat Dec 19 19:48:58 EST 2015


   *
   Hi,

   I am starting with Python object oriented concepts and have difficulty in
   understanding object instantiation. Below is an example code that I am
   trying to think/implement. I can create a given student object based on
   given firstname, lastname and grade. How do I find all objects matching
   particular criteria and return them to caller? Do I need to iterate/select
   through some list/database and create Student objects again?

   *

   Sorry that question is not quite clear, but I am confused and not sure how
   to put it in right words.*

   *

   class Student():
   * def __init__(self,firstname,lastname,age):
   * * self.firstname = firstname
   * * self.lastname = lastname
   * * self.grade = grade

   * def set_grade(self,grade):
   * * self.grade = grade

   * @classmethod

   * # Find all Students with given lastname
   * def find_by_lastname():
   * * # How do I return all student objects that have same lastname?
   * * # Do I need to call init method again? I am confused here.
   * * pass

   *

   Thanks,

   Jamie

   *
   *


More information about the Tutor mailing list