creating and naming objects
Brian
bnblazer at gmail.com
Wed Jun 7 12:05:58 EDT 2006
I have a question that some may consider silly, but it has me a bit
stuck and I would appreciate some help in understanding what is going
on.
For example, lets say that I have a class that creates a student
object.
Class Student:
def setName(self, name)
self.name = name
def setId(self, id)
self.id = id
Then I instantiate that object in a method:
def createStudent():
foo = Student()
/add stuff
Now, suppose that I want to create another Student. Do I need to name
that Student something other than foo? What happens to the original
object? If I do not supplant the original data of Student (maybe no id
for this student) does it retain the data of the previous Student
object that was not altered? I guess I am asking how do I
differentiate between objects when I do not know how many I need to
create and do not want to hard code names like Student1, Student2 etc.
I hope that I am clear about what I am asking.
Thanks,
Brian
More information about the Python-list
mailing list