From 38cef54ddc803fc63c9fbfdad891c2e0a12acdee Mon Sep 17 00:00:00 2001 From: Jason Paryani Date: Tue, 3 Sep 2013 01:16:48 -0700 Subject: [PATCH] Update docs with new import method --- README.md | 7 +++---- docs/quickstart.rst | 16 ++++++++-------- examples/example.py | 7 +++---- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 3492370..56c0cfe 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,10 @@ 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')) +import addressbook_capnp def writeAddressBook(file): - addresses = addressbook.AddressBook.new_message() + addresses = addressbook_capnp.AddressBook.new_message() people = addresses.init('people', 2) alice = people[0] @@ -77,7 +76,7 @@ def writeAddressBook(file): def printAddressBook(file): - addresses = addressbook.AddressBook.read(file) + addresses = addressbook_capnp.AddressBook.read(file) for person in addresses.people: print(person.name, ':', person.email) diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 4c5e1f1..5b6a9b6 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -16,12 +16,13 @@ First you need to import the library:: Then you can load the Cap'n Proto schema with:: - addressbook = capnp.load('addressbook.capnp') + import addressbook_capnp -Note that we assign the loaded module to a variable, named `addressbook`. We'll use this from now on to access the Cap'n Proto schema, ie. when we need to get a Struct's class or accessing const values. - -You can also provide an absolute path to the Cap'n Proto schema you wish to load. Otherwise, it will only look in the current working directory. +This will look all through all the directories in your sys.path/PYTHONPATH, and try to find a file of the form 'addressbook.capnp'. If you want to disable the import hook magic that `import capnp` adds, and load manually, here's how:: + capnp.remove_import_hook() + addressbook_capnp = capnp.load('addressbook.capnp') + For future reference, here is the Cap'n Proto schema. Also available in the github repository under `examples/addressbook.capnp `_:: # addressbook.capnp @@ -207,11 +208,10 @@ Here is a full example reproduced from `examples/example.py