[Tutor] Hi I need advice

Edy Lie ed@iterunet.com
Wed, 7 Nov 2001 16:55:53 +0800


Hi everyone.

   I need some help/advice over the following code. My 1st attempt using
class.

#!/usr/local/bin/python
import sys

class DataBase:
   def __init__(self, Plan, Domain, Email, Name):
      self.UserPlan = Plan
      self.UserDomain = Domain
      self.UserEmail = Email
      self.UserName = Name

print '1. Adding New User'
print '2. Search New User'
print '3. View All User'
print '4. Exit'
choice = input("Please choose an option: ")

if choice == 1:
    print 'Adding New User\n'
    add = DataBase(' ', ' ', ' ', ' ')
    add.UserPlan = raw_input("Plan: ")
    add.UserDomain = raw_input("Domain: ")
    add.UserEmail = raw_input("Email: ")
    add.UserName = raw_input("Name: ")
    print "Domain %s has registered" % add.UserDomain
    save = raw_input("Do you wanna save? Press Y or N\nChoice: ")
    if save == "Y":
       print "Record Saved\n"
       f=open('record', 'w')
       f.write("Plan: %s\nDomain: %s\nEmail: %s\nName: %s\n-----\n" %
(add.UserPlan,add.UserDomain
,add.UserEmail,add.UserName))
    elif save == "N":
       print "No Data Saved\n"
    else:
       print "Wrong input ... Bye Bye\n"
       sys.exit()

elif choice == 2:
    print 'Search New User\n'


elif choice == 3:
    print 'View All User\n'

elif choice == 4:
    print 'Exit program ...'
    sys.exit()

else:
    print 'Wrong input'
    sys.exit()

My question is why do i can't to use add = DataBase() ?

Thanks

Edy Lie.