§ 4.65 - [postparse] Built-InMnemonic aid: postparse for POST (after) PARSE pretty-print Python source See also: [pythparse] This built-in allows you to generate a pretty-printed representation of Python source code. In the example, you'll see I wrapped a <div> with a black background around the [postparse] , as the default pretty-printing colors were selected with a black background in mind: [postparse content] <div style="background: #000000; padding: 1em;"> [postparse def mygen(n): for i in range(0,n): print "hello!" ] </div> <div style="background: #000000; padding: 1em;"><span style="color: #00ff00"><span style="color: #ff00ff">def</span> mygen<span style="color:#ff8844;">(</span>n<span style="color:#ff8844;">)</span><span style="color:#00ffff;">:</span></span> <span style="color: #00ff00"> <span style="color: #ff00ff">for</span> i <span style="color: #ff00ff">in</span> range<span style="color:#ff8844;">(</span>0<span style="color:#00ffff;">,</span>n<span style="color:#ff8844;">)</span><span style="color:#00ffff;">:</span></span> <span style="color: #00ff00"> <span style="color: #ff00ff">print</span> </span><span style="color: #ffffff">"</span><span style="color: #ff0000">hello!</span><span style="color: #ffffff">"</span><span style="color: #00ff00"></span></div> def mygen(n):
for i in range(0,n):
print "hello!" You can use aa_macro code within the scope of Python source code fed to [postparse] at any parsing level, not just the top context; this can be very handy, but it comes with a bit of work, too: You have to change all the Python source occurances of [ and ] to [lb] and [rb] , and all of the occurances of { and } to [ls] and [rs] , or aa_macro will try to parse the Python as aa_macro, and the result of that won't be pretty. With that in mind, it is sometimes more practical to use [pythparse] , store the result in a variable, and then use the variable in deeper aa_macro contexts. You can control what the pretty printing does in terms of styling by setting the following variables (default values are shown):
Keyboard Navigation
, Previous Page . Next Page t TOC i Index |