Sunday, September 6, 2009

Retaining WhiteSpace When Posting Python Code

To post python code in a blog (html) and retain the line whitespace that is required in order for the code to remain unambiguous, simply enclose your code within pre html tag block.

The 'pre' tag yields a fixed-width (monospace) font, and preserves spaces and line-breaks.

<pre>

def doStuff(i):
print()
for z in range(i):
print(z)

c = 4

for z in range(c):
doStuff(z)

</pre>

No comments:

Post a Comment

comment: