Syntax highlighting and self replicating machines
So the other day I went to the Auckland Makers-Space. There they had a 3d printer printing out replacement parts for itself. The guy told me that in fact all the parts of his 3d printer had been created by his friends 3d printer. Talk about exponential growth of 3d printers. (Check out ponoko to access one)
Anyway I decided to write a how-to article on how I style my python code snippets. firstly easy_install Pygments, then:
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter
code = open(__file__).read()
print highlight(code, PythonLexer(), HtmlFormatter())
#print HtmlFormatter().get_style_defs('.highlight')
The above code snippet, through the use of __file__, prints the following html source which in turn produces the above code snippet:
of course relevant css is required which you can see in my blogs css file.
On another level, pypy does something similar with its translator (and i'm not talking about lexing).. Watch the few minutes leading up to 29min,50 seconds

