Jan Tattermusch пре 10 година
родитељ
комит
b95670f5fb
2 измењених фајлова са 5 додато и 5 уклоњено
  1. 2 2
      examples/add_person.py
  2. 3 3
      examples/list_people.py

+ 2 - 2
examples/add_person.py

@@ -19,7 +19,7 @@ def PromptForAddress(person):
     if number == "":
       break
 
-    phone_number = person.phone.add()
+    phone_number = person.phones.add()
     phone_number.number = number
 
     type = raw_input("Is this a mobile, home, or work phone? ")
@@ -50,7 +50,7 @@ except IOError:
   print sys.argv[1] + ": File not found.  Creating a new file."
 
 # Add an address.
-PromptForAddress(address_book.person.add())
+PromptForAddress(address_book.persons.add())
 
 # Write the new address book back to disk.
 f = open(sys.argv[1], "wb")

+ 3 - 3
examples/list_people.py

@@ -7,13 +7,13 @@ import sys
 
 # Iterates though all people in the AddressBook and prints info about them.
 def ListPeople(address_book):
-  for person in address_book.person:
+  for person in address_book.persons:
     print "Person ID:", person.id
     print "  Name:", person.name
-    if person.HasField('email'):
+    if person.email != "":
       print "  E-mail address:", person.email
 
-    for phone_number in person.phone:
+    for phone_number in person.phones:
       if phone_number.type == addressbook_pb2.Person.MOBILE:
         print "  Mobile phone #:",
       elif phone_number.type == addressbook_pb2.Person.HOME: