Saturday 4 October 2014

Formatting Python Code for the Web with Pygments

I've been unsatisfied with Blogger's lack of easy handling for code formatting.  To fix this I installed Pygments.  I can now type,

pygmentize -f html -O noclasses count-slow.py

...and end up with output that I can paste into the Blogger HTML editor window.

The result is something like this:

"""
Count to 20 in one second steps
"""
from time import sleep

for i in range(1,20):
    print(str(i))
    sleep(1)




No comments: