19 email =
raw_input(
"Enter email address (blank for none): ")
24 number =
raw_input(
"Enter a phone number (or leave blank to finish): ")
28 phone_number = person.phones.add()
29 phone_number.number = number
31 type =
raw_input(
"Is this a mobile, home, or work phone? ")
33 phone_number.type = addressbook_pb2.Person.MOBILE
35 phone_number.type = addressbook_pb2.Person.HOME
37 phone_number.type = addressbook_pb2.Person.WORK
39 print(
"Unknown phone type; leaving as default value.")
45 if len(sys.argv) != 2:
46 print(
"Usage:", sys.argv[0],
"ADDRESS_BOOK_FILE")
49 address_book = addressbook_pb2.AddressBook()
53 with open(sys.argv[1],
"rb")
as f:
54 address_book.ParseFromString(f.read())
56 print(sys.argv[1] +
": File not found. Creating a new file.")
62 with open(sys.argv[1],
"wb")
as f:
63 f.write(address_book.SerializeToString())