def add_friend(): new_friend = { 'name': " ", 'salutation': " ", 'age': 0, 'rating': 0.0, 'is_online': True, 'chats': [] } new_friend['name'] = raw_input("Enter a friend name ") new_salutation = raw_input("what should call your friend(mr./miss.)? ") new_friend['name'] = new_salutation + " " + new_friend['name'] new_friend['age'] = int(input("Enter your friend age ")) new_friend['rating'] = float(raw_input("Enter your friend rating? ")) if len(new_friend['name'] ) > 0 and new_friend['age'] > 12 and new_friend['age'] < 60: friend.append(new_friend) with open("db.csv", 'a') as friend_data: # a append friends in a file writer = csv.writer(friend_data) writer.writerow([ new_friend["name"], new_friend["salutation"], new_friend["age"], new_friend["rating"], new_friend["is_online"] ]) else: print("sorry! your friend does not must one invalid to be spy user") return len(friend)
def load_friends(): with open("db.csv", 'rb') as friends_data: reader = csv.reader(friends_data) for row in reader: new_friend = { 'name': row[0], 'salutation': row[1], 'age': row[2], 'rating': row[3], 'is_online': row[4] } friend.append(spy_friend)
def add_friend(): new_friend = Spy('', '', 0, 0.0) new_friend.name = raw_input('Enter your Friend Name: ') new_friend.salutation = raw_input('Enter your Friend Salutation:') new_friend.age = int(input('Enter your Friend Age: ')) new_friend.rating = float(input('Enter your Ratings: ')) # present_status = True if len(new_friend.name) > 0 and new_friend.name.isalpha( ) and new_friend.age > 13 and new_friend.age < 90: friend.append(new_friend) with open('db.csv', 'a') as frnd_data: writer = csv.writer(frnd_data) writer.writerow([ new_friend.name, new_friend.salutation, new_friend.age, new_friend.rating ]) else: print("Your Entered Details dosen't match with your Friend ") return len(friend)
def load_friend(): with open('db.csv', 'rb') as frnd_data: reader = csv.reader(frnd_data) for row in reader: new_friend = Spy(row[0], row[1], row[2], row[3]) friend.append(new_friend)