$ pygmentize -O full -O style=native -o test.html test.py
Yüklemek için Pygments:
$ easy_install Pygments
Bir kitaplık olarak kullanabilirsiniz.
from pygments import highlight
from pygments.lexers import guess_lexer
from pygments.formatters import HtmlFormatter
code = '#!/usr/bin/python\nprint "Hello World!"'
lexer = guess_lexer(code) # or just pygments.lexers.PythonLexer()
formatter = HtmlFormatter(noclasses=True, nowrap=True, lineseparator="<br>\n")
print highlight(code, lexer, formatter)
Çıktı:
<span style="color: #408080; font-style: italic">#!/usr/bin/python</span><br>
<span style="color: #008000; font-weight: bold">print</span>
<span style="color: #BA2121">"Hello World!"</span><br>
(Netlik eklenmiş boşluk)
Html gibi:
#!/usr/bin/python
print
"Hello World!"