Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: third_party/protobuf/examples/list_people.py

Issue 1842653006: Update //third_party/protobuf to version 3. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #! /usr/bin/env python
2
3 # See README.txt for information and build instructions.
4
5 import addressbook_pb2
6 import sys
7
8 # Iterates though all people in the AddressBook and prints info about them.
9 def ListPeople(address_book):
10 for person in address_book.people:
11 print "Person ID:", person.id
12 print " Name:", person.name
13 if person.email != "":
14 print " E-mail address:", person.email
15
16 for phone_number in person.phones:
17 if phone_number.type == addressbook_pb2.Person.MOBILE:
18 print " Mobile phone #:",
19 elif phone_number.type == addressbook_pb2.Person.HOME:
20 print " Home phone #:",
21 elif phone_number.type == addressbook_pb2.Person.WORK:
22 print " Work phone #:",
23 print phone_number.number
24
25 # Main procedure: Reads the entire address book from a file and prints all
26 # the information inside.
27 if len(sys.argv) != 2:
28 print "Usage:", sys.argv[0], "ADDRESS_BOOK_FILE"
29 sys.exit(-1)
30
31 address_book = addressbook_pb2.AddressBook()
32
33 # Read the existing address book.
34 f = open(sys.argv[1], "rb")
35 address_book.ParseFromString(f.read())
36 f.close()
37
38 ListPeople(address_book)
OLDNEW
« no previous file with comments | « third_party/protobuf/examples/list_people.go ('k') | third_party/protobuf/examples/list_people_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698