[Tutor] OOP Newbie Q
Alan Colburn
aicolburn@yahoo.com
Mon, 1 Jul 2002 10:28:47 -0700 (PDT)
Hi all--
As I work through various tutorials, trying to
understand OOP fundamentals, I keep bumping into the
same question -- how do you set up a user interfact to
instatiate (or create :-) multiple objects of the same
type?
An example would probably make my question clearer. In
honor of Alan Gauld's nice tutorial, I'll use his OOP
example -- a program to work with bank accounts, via a
class called BankAccount. To create a new account
object, of course, you just write:
<object name>=BankAccount()
filling <object name> with a different name for each
account holder. Presumably a bank would have hundreds
of BankAccount objects in its program.
My question is about how I'd set up a user interface
to create a new account. How can you create a new
object without having to manually enter the source
code each time?
a=BankAccount()
b=BankAccount()
c=BankAccount()
This would get a bit tedious after awhile! I get stuck
because if you ask the user for info that could lead
to an account name, with something like the raw_input
statement, the resulting information is string type,
so I can't use it to create the object. In other
words, code like this wouldn't work for creating a new
BankAccount object:
acctName=raw_input("Account name? ")
acctName=BankAccount()
Any thoughts? Thanks! -- Al C.
__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com