1
pygments를 사용하여 코드를 강조 표시하고 싶습니다. 기본적으로 JSON 객체의 거대한 목록입니다. 여기에 내가 시도 내용은 다음과 같습니다문자열을 조각화 렉서로 스트리밍 하시겠습니까?
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'
분명이 잘못된 인터페이스 :
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())
이
나에게 다음과 같은 오류를했다. 올바른 것이 무엇일까?