ok. i am making this program called Human_Data to store peoples info on your computer. bwahaha.
i need help with opening and reading peoples info, stored in a profile class. i am also confused with instances of classes.
here is the code.
#----------------------------------|
#Copyright Muffinware 2011 |
#Human Data and all Muffinware |
#products are trademarked to |
#Muffinware.net and all its |
#sub domains. |
# ~~~ |
# \_/ |
#----------------------------------|
import sys
import pickle
class Profile():
def __init__(self):
self.firstname = ""
self.lastname = ""
self.age = ""
self.gender = ""
self.haircolor = ""
self.eyecolor = ""
self.height = ""
self.weight = ""
self.notes = ""
def make_firstname(self):
self.firstname = raw_input('First Name: ')
def make_lastname(self):
self.lastname = raw_input('Last Name: ')
def make_age(self):
self.age = raw_input('Age: ')
def make_gender(self):
self.gender = raw_input('Gender (male or female): ')
def make_haircolor(self):
self.haircolor = raw_input('Hair Color: ')
def make_eyecolor(self):
self.eyecolor = raw_input('Eye Color: ')
def make_height(self):
self.height = raw_input('Height (in inches please): ')
def make_weight(self):
self.weight = raw_input('Weight: ')
def make_notes(self):
self.notes = raw_input('Any other notes on the person?: ')
def display(self):
print ""
print ""
print self.lastname+", "+self.firstname
print "is "+self.age
print "is "+self.gender
print "has "+self.haircolor+" hair"
print "has "+self.eyecolor+" colored eyes"
print "is "+self.height+" inches tall"
print "is "+self.weight+" pounds"
print "Notes: "+self.notes
def change(self, change):
if change == "firstname":
profile.make_firstname()
elif change == "lastname":
profile.make_lastname()
elif change == "age":
profile.make_age()
elif change == "gender":
profile.make_gender()
elif change == "haircolor":
profile.make_haircolor()
elif change == "eyecolor":
profile.make_eyecolor()
elif change == "height":
profile.make_height()
elif change == "weight":
profile.make_weight()
elif change == "notes":
profile.make_notes()
else:
print "please try again later"
def save(self):
profilefile = open(self.firstname+self.lastname, "w")
pickle.dump(self, profilefile)
profilefile.close()
def open(self, first, last):
file_name = first+last
f = open(file_name, "r")
profile = pickle.load(f)
if __name__ == "__main__":
print "welcome to human data!"
x = 4
while x == 4:
profile = Profile()
print "would you like to: create a new profile (1), view existing ones (2), or exit (3)"
pick = input(': ')
if pick == 1:
profile.make_firstname()
profile.make_lastname()
profile.make_age()
profile.make_gender()
profile.make_haircolor()
profile.make_eyecolor()
profile.make_height()
profile.make_weight()
profile.make_notes()
profile.display()
a = True
while a:
print "Are these facts ok? Y/N "
choice = raw_input('')
if choice == "n":
print "what yould you like to change?"
print "no spaces please, (like eyecolor rather than eye color)"
change = raw_input('')
profile.change(change)
elif choice == "y":
a = False
print "saving..."
profile.save()
elif pick == 2:
first = raw_input('first name:')
last = raw_input('last name:')
profile.open(first, last)
profile.display()
print "would you like to change anything? Y/N"
choice = raw_input(': ')
if choice == "y":
print "no spaces please!"
change = raw_input('What would you like to change?: ')
profile.change(change)
elif choice == "n":
print "OK then!"
break
elif pick == 3:
sys.exit(0)