1
Ich möchte mit Hilfe von Segmenten Code für mich markieren - im Grunde eine riesige Liste von JSON-Objekten. Hier ist, was ich versucht:Stream eine Zeichenfolge in pygents lexer?
from pygments.lexers import JsonLexer
from pygments.formatters import HtmlFormatter
from pygments import highlight
import StringIO
f = StringIO.StringIO()
f.write('a')
f.seek(0)
print highlight(f, JsonLexer(), HtmlFormatter())
Das gab mir die folgende Fehlermeldung:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/d33tah/virtualenv/lib/python2.7/site-packages/pygments/__init__.py", line 87, in highlight
return format(lex(code, lexer), formatter, outfile)
File "/home/d33tah/virtualenv/lib/python2.7/site-packages/pygments/__init__.py", line 45, in lex
return lexer.get_tokens(code)
File "/home/d33tah/virtualenv/lib/python2.7/site-packages/pygments/lexer.py", line 151, in get_tokens
text, _ = guess_decode(text)
File "/home/d33tah/virtualenv/lib/python2.7/site-packages/pygments/util.py", line 309, in guess_decode
text = text.decode('utf-8')
AttributeError: StringIO instance has no attribute 'decode'
Dies ist eindeutig falsch Schnittstelle. Was wäre der richtige?