Code highlighting for Python and others
After struggling for a while to highlight Python code without having to install a package or taking screenshots I found this awesome tool: Online syntax highlighting for “Python”. It is also very useful to highlight code that is freely available in the web. Hope to see R extensions soon.
Another option for Wordpress.com is to use the this wrapper. As an example check this Python code to calculate the mean center and deviational ellipses in ArcGIS. The only problem is with the indenting for the loop it has some trouble recognizing the format.
[sourcecode language=”python”]
#Calculate the mean center and deviational ellipse for several variables programatically
#Author Jose Gonzalez
import arcpy
from arcpy import env
from datetime import datetime
try:
# Set environment settings
env.workspace = “U:/advGIS/Lab9/Lab9.gdb/Layers”
print "Working"
print datetime.now()
# Local variables:
inFeatures = “master2006cut”
# Process: Select
arcpy.Select_analysis(inFeatures, “Penninsula”, “”ENTIDAD” = 4 OR “ENTIDAD” =23 OR “ENTIDAD” =31")
for i in [“VTURNOUT”, “PCTVPAN”, “PCTVAPM”, “PCTVPBT”]:
# Process: Mean Center
arcpy.MeanCenter_stats(inFeatures, i + “_MeanCenter”, i, “”, “”)
# Process: Directional Distribution (Standard Deviational Ellipse)
arcpy.DirectionalDistribution_stats(inFeatures, i + “_DevEllipse”, “1_STANDARD_DEVIATION”, i, “”)
print inFeatures
print datetime.now()
except Exception, e:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
print "Line %i" % tb.tb_lineno
print e.message
[/sourcecode]