Fix up example for python3
This commit is contained in:
19725
capnp/capnp.cpp
19725
capnp/capnp.cpp
File diff suppressed because it is too large
Load Diff
48862
capnp/schema.cpp
48862
capnp/schema.cpp
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,11 @@
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import capnp
|
||||
|
||||
this_dir = os.path.dirname(__file__)
|
||||
addressbook = capnp.load(os.path.join(this_dir, 'addressbook.capnp'))
|
||||
|
||||
|
||||
def writeAddressBook(fd):
|
||||
message = capnp.MallocMessageBuilder()
|
||||
addressBook = message.initRoot(addressbook.AddressBook)
|
||||
@@ -33,27 +36,28 @@ def writeAddressBook(fd):
|
||||
f = open('example', 'w')
|
||||
writeAddressBook(f.fileno())
|
||||
|
||||
|
||||
def printAddressBook(fd):
|
||||
message = capnp.PackedFdMessageReader(f.fileno())
|
||||
addressBook = message.getRoot(addressbook.AddressBook)
|
||||
|
||||
for person in addressBook.people:
|
||||
print person.name, ':', person.email
|
||||
print(person.name, ':', person.email)
|
||||
for phone in person.phones:
|
||||
print phone.type, ':', phone.number
|
||||
print(phone.type, ':', phone.number)
|
||||
|
||||
which = person.employment.which()
|
||||
print which
|
||||
print(which)
|
||||
|
||||
if which == addressbook.Person.Employment.Which.UNEMPLOYED:
|
||||
print 'unemployed'
|
||||
print('unemployed')
|
||||
elif which == addressbook.Person.Employment.Which.EMPLOYER:
|
||||
print 'employer:', person.employment.employer
|
||||
print('employer:', person.employment.employer)
|
||||
elif which == addressbook.Person.Employment.Which.SCHOOL:
|
||||
print 'student at:', person.employment.school
|
||||
print('student at:', person.employment.school)
|
||||
elif which == addressbook.Person.Employment.Which.SELF_EMPLOYED:
|
||||
print 'self employed'
|
||||
print
|
||||
print('self employed')
|
||||
print()
|
||||
|
||||
f = open('example', 'r')
|
||||
printAddressBook(f.fileno())
|
||||
|
||||
Reference in New Issue
Block a user