Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fixed readme and selectors tutorial

  • Loading branch information...
commit aafae5a3b9cc3f6a87f1228a8524c381080ebea6 1 parent ce858e9
Erez Sh authored

Showing 2 changed files with 6 additions and 6 deletions. Show diff stats Hide diff stats

  1. +5 5 README.md
  2. +1 1  docs/selectors.md
10 README.md
Source Rendered
@@ -106,16 +106,16 @@ Let's pretty-print it! We can use a transformer to do it. A transformer is a tre
106 106
107 107 >>> class PrettyINI(plyplus.STransformer):
108 108 def option(self, tree):
109   - name = tree.select('name *')[0]
110   - value = tree.select('value *')[0]
  109 + name = tree.select1('name *') # select1 asserts only one result
  110 + value = tree.select1('value *')
111 111 return '%s = %s' % (name, value)
112 112 def section(self, tree):
113   - name = tree.select('name *')[0]
  113 + name = tree.select1('name *')
114 114 return '[%s]\n\t%s' % (name, '\n\t'.join(tree.tail[1:]))
115 115
116 116 Now that each rule has code to handle it, let's run it!
117 117
118   - >>> meta = t.select('=section /meta/')[0]
  118 + >>> meta = t.select1('=section /meta/')
119 119 >>> print PrettyINI().transform( meta )
120 120 [meta]
121 121 Name = npymath
@@ -124,7 +124,7 @@ Now that each rule has code to handle it, let's run it!
124 124
125 125 It works! Now that it's done, we can use it to output the rest of the file as well:
126 126
127   - >>> print '\n'.join( PrettyINI().transform(t) )
  127 + >>> print '\n'.join( PrettyINI().transform(t).tail )
128 128 ... (left as an excercise to the reader ;)
129 129
130 130
2  docs/selectors.md
Source Rendered
@@ -67,7 +67,7 @@ Wait! Why did we get "basestring" twice? And why is "isinstance" there? It's not
67 67
68 68 How about all of the keyword arguments used? (notice they are pairs of names inside an "arg" head)
69 69
70   - >>> arg =name + *
  70 + >>> x.select('arg =name + *')
71 71 [name('isinstance'), name('shell'), name('bufsize'), name('stdin'), name('stdout'), name('close_fds')]
72 72
73 73 ## Afterword

0 comments on commit aafae5a

Please sign in to comment.
Something went wrong with that request. Please try again.