creating and naming objects

Gerard Flanagan grflanagan at yahoo.co.uk
Wed Jun 7 14:08:37 EDT 2006


Brian wrote:
> Thank you all for your response.  I think that I am getting it.  Based
> on those responses, would I be correct in thinking that this would be
> the way to initialize my Student object and return the values?
>
> class Student:
>     def __init__(self, name, id):
>         self.name = name
>         self.id = id
>
>     def getName(self):
>         return self.name
>
>     def getId(self):
>         return self.id
>
> Additionally, correct me if I am wrong but I can recycle:
>
> foo = Student()
>
> And doing so will just create a new instance of Student (with whatever
> attributes it is given) and the original foo is gone?
>
> Thanks for your help and patience.  After reading my original post and
> then this one, I could see that it may look suspiciously like a home
> work assignment.  Trust me it's not.  The student example just seemed
> like a good fit to discuss this.
>
> Thanks again,
> Brian

Here's a page from the Python tutorial wiki which may be helpful to
you:

  http://pytut.infogami.com/node11-baseline.html

It's an introduction to classes which, appositely, uses a Student class
as an example.  Still a work in progress.  Feel free to leave a comment
if you find it helpful or not - your input would be very much valued.
(Note the StudentTracker class).

Gerard




More information about the Python-list mailing list