§ 4.67 - [pythparse] Built-InMnemonic aid: pythparse for PYTHon PARSE pretty-print Python source to variable
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. [pythparse content] [pythparse def mygen(n): names = ['Ben','Deb'] for i in range(0,n): print "hello" + names[0] and names[1] ] <div style="background: #000000;"> [v loc_pyth] </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"> names <span style="color:#00ffff;">=</span> <span style="color:#ff8844;">[lb]</span></span><span style="color: #ffffff">'</span><span style="color: #88ff44">Ben</span><span style="color: #ffffff">'</span><span style="color: #00ff00"><span style="color:#00ffff;">,</span></span><span style="color: #ffffff">'</span><span style="color: #88ff44">Deb</span><span style="color: #ffffff">'</span><span style="color: #00ff00"><span style="color:#ff8844;">[rb]</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: #88ff44">hello</span><span style="color: #ffffff">"</span><span style="color: #00ff00"> <span style="color:#00ffff;">+</span> names<span style="color:#ff8844;">[lb]</span>0<span style="color:#ff8844;">[rb]</span> <span style="color: #ff00ff">and</span> names<span style="color:#ff8844;">[lb]</span>1<span style="color:#ff8844;">[rb]</span></span></div> def mygen(n):
names = ['Ben','Deb']
for i in range(0,n):
print "hello" + names[0] and names[1]
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 February 18th, 2026 at 12:52 MT |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||