§ 4.66 - [pythparse] Built-InMnemonic aid: pythparse See also: [pythparse] ) This built-in allows you to generate a pretty-printed representation of Python source code to a local variable, loc_pyth. In the example, you'll see I wrapped a <div> with a black background around the retrieval of the loc_pyth variable, as the default pretty-printing colors were selected with a black background in mind. There are some details to consider here; please refer to the notes below the examples on this page. def mygen(n):
names = ['Ben','Deb']
for i in range(0,n):
print "hello" + names[0] and names[1] Warning:
[pythparse] ) must be used at the top level; you can't embed it in a style or another built-in. It can handle Python code without any changes, but again, only in the top level context. Caution:
Although [pythparse] ) takes raw Python, the aa_macro parser still has to wade through it to find the closing ] for the [pythparse] ) built-in itself. So if there are unbalanced [] or {} anywhere in the Python source, that will break the parsing. An easy fix for this is to balance to a pair in the comments before (if ] or }) or after (if [ or {) the line of Python. Sorry about that, but it's inherent in how all this works. Because of this, it may be more convenient to edit all the occurrences of [, ], { and } to [lb] ) , [rb] ) , [ls] ) and [rs] ) and then use [postparse] ) instead. It's basically a tradeoff between getting a perfect code representation and having to do some manipulating of comments as described here. One last thing: If you are displaying Python that contains aa_macro source, you should definitely use [pythparse] ) ; this is because [postparse] ) will actually process anything like that that it finds. 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 on January 10th, 2026 at 2:38 MT |
|||||||||||||||||||||||||||||||||||||||||||||||||