Search This Blog

Sunday, October 1, 2017

Testing and using Pygments library for code visualization

print "Hello World"

The code above is from javascript code generated from Pygments.org project written to write and visualize code. I need special format for coding simply to distinguish from text. It is simple to do by installing package package from cmd with "pip install" command. Pip is very convenient to install, upgrade and uninstall python packages. Fast and convenient. So Pygments.org have documentation how to install and trial window for code generation. I will use in this blog sample codes, but can adjust it the way you want and use for it many programming languages.


print "Mindaugas antras kodas"

I write the code above using Pygments.org site Example. The code generate javascript code on cmd and copy all window to note and use javascript code to place to blog HTML code.  There are many options to visualize code, but I will do it later. For know you can write codes to blog.

So continuing in Pygments.org documentation on command line usage part you can find commands how to write python colourful script on cmd or HTML file. It is simple to use - using python file folder environment you can write via command prompt with library function any code. 
Now I will write instruction how to make codes colourful and upload to your websites. It will look you work for Wikipedia
So on cmd with command cd Folderpath select folder environment and use full HTML file command from Command line usage site to selecting from command line usage "pygmentize -f html -O full -o test.html test.py". Change test to you Script name. And you will get in your folder HTML file with colorful code. Open HTML file with Notepad, copy all code and past to blog's post HTML page. That's it.


from glob2 import glob

with open('total.txt', 'a') as singleFile:
    for csvFile in glob('*.txt'):
        for line in open(csvFile, 'r'):
           singleFile.write(line)

#cd C:\Python27
#python APPENDCSV.py

No comments: