Colorizing Python Source Using the Built-in Tokenizer

/ Published in: Python
Save to your folder(s)

You need to convert Python source code into HTML markup, rendering comments, keywords, operators, and numeric and string literals in different colors.
tokenize.generate_tokens does most of the work. We just need to loop over all tokens it finds, to output them with appropriate colorization:


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.