0

Can i highlight the print raster in different color? Below I have attached the shapshot, where i trying to highlight in different color only print raster, I have underlined where i trying to put different color, I am running program on Arc GIS python window.

enter image description here

Code i am running : Instead of getting all result by print white color, i just want to print raster name in different color while its printing the name of raster along with statistics valu , so its easy to find out each raster

import arcpy
arcpy.env.workspace = r"D:\2008\JANUARY"
rasterList = arcpy.ListRasters()

for raster in rasterList:
     rasterObj = arcpy.Raster(raster)
     print raster

     bands = arcpy.GetRasterProperties_management(raster, "MEAN")
     print "MEAN VALUE: %s" %bands

My desire output, i have attached below. i highlight manually by yellow color, i just want to put some code to define the color of list of raster

enter image description here

2

This doesn't work in the Python Window, but does work in the script tool dialog that displays while a tool is running:

arcpy.AddMessage("This is a message")

A Message will display in default colour

arcpy.AddWarning("This is a warning")

A Warning will display in a different colour (default appears to be green)

enter image description here

You can also issue an Error message, which will display in red, however this will also indicate a script failure even if the script is successful

arcpy.AddError("This is an error")

enter image description here

  • I like your lateral thinking for a two or three colour workaround in the tool's results dialog. – PolyGeo Sep 4 '16 at 5:51
2

I do not believe that it is possible from Python code, to specify to the Python window of ArcMap which it is being run in, what color the strings being printed using print statements will be coloured.

In any event, I think your question distils to:

If I run the code below to print output to ArcMap's Python window, is it possible for me to specify that "test1" will be in a red font, while "test2" will be in a blue font?

print "test1"
print "test2"

At Stack Overflow I found and tested without success within the Python window of ArcMap some of the answers at https://stackoverflow.com/questions/287871/print-in-terminal-with-colors-using-python.

When I want to show "headings" in printed output like this I tend to just place asterisks either side to make them stand out e.g. to make "test1" standout from "test2":

print "** {0} **".format("test1")
print "test2"
  • i have added a snapshot , what acually i am trying to do with that – Shouvik Jha Sep 4 '16 at 5:39
  • Is it possible to do something like print.color? – Shouvik Jha Sep 4 '16 at 5:41
  • 1
    @ShouvikJha When it is so easy to test I think you should. – PolyGeo Sep 4 '16 at 5:42
  • 1
    It can be worth testing even a guess, but when I guess I test before asking others if they think my guess will work. – PolyGeo Sep 4 '16 at 5:59
  • 1
    Your suggestion of using asterisks is a good one. I tend to indent following lines using print "\ttest2" so the un-indented headings stand out also – Midavalo Sep 4 '16 at 6:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.