Skip to content

Commit

Permalink
fixed readme and selectors tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
Erez Sh committed Sep 30, 2012
1 parent ce858e9 commit aafae5a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ Let's pretty-print it! We can use a transformer to do it. A transformer is a tre


>>> class PrettyINI(plyplus.STransformer): >>> class PrettyINI(plyplus.STransformer):
def option(self, tree): def option(self, tree):
name = tree.select('name *')[0] name = tree.select1('name *') # select1 asserts only one result
value = tree.select('value *')[0] value = tree.select1('value *')
return '%s = %s' % (name, value) return '%s = %s' % (name, value)
def section(self, tree): def section(self, tree):
name = tree.select('name *')[0] name = tree.select1('name *')
return '[%s]\n\t%s' % (name, '\n\t'.join(tree.tail[1:])) return '[%s]\n\t%s' % (name, '\n\t'.join(tree.tail[1:]))


Now that each rule has code to handle it, let's run it! Now that each rule has code to handle it, let's run it!


>>> meta = t.select('=section /meta/')[0] >>> meta = t.select1('=section /meta/')
>>> print PrettyINI().transform( meta ) >>> print PrettyINI().transform( meta )
[meta] [meta]
Name = npymath Name = npymath
Expand All @@ -124,7 +124,7 @@ Now that each rule has code to handle it, let's run it!


It works! Now that it's done, we can use it to output the rest of the file as well: It works! Now that it's done, we can use it to output the rest of the file as well:


>>> print '\n'.join( PrettyINI().transform(t) ) >>> print '\n'.join( PrettyINI().transform(t).tail )
... (left as an excercise to the reader ;) ... (left as an excercise to the reader ;)




Expand Down
2 changes: 1 addition & 1 deletion docs/selectors.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Wait! Why did we get "basestring" twice? And why is "isinstance" there? It's not


How about all of the keyword arguments used? (notice they are pairs of names inside an "arg" head) How about all of the keyword arguments used? (notice they are pairs of names inside an "arg" head)


>>> arg =name + * >>> x.select('arg =name + *')
[name('isinstance'), name('shell'), name('bufsize'), name('stdin'), name('stdout'), name('close_fds')] [name('isinstance'), name('shell'), name('bufsize'), name('stdin'), name('stdout'), name('close_fds')]


## Afterword ## Afterword
Expand Down

0 comments on commit aafae5a

Please sign in to comment.