Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Redirect "print" statements to a file

Posted on 2009-07-15
9
Medium Priority
?
258 Views
Last Modified: 2012-05-07
Hello,
Please see the script below. I'd like to save to file the the 'zmax' output plus the name of the raster image on a single line. Each iteration would be the next line in the same out file. Can this script be modified to do so? If so how?

e.g.

Name1 100
Name2 101
etc

Currently the output to screen looks like this:
C:\Documents and Settings\u4cncmgj>c:\python24\python.exe "C:\Documents and Sett
ings\u4cncmgj\Desktop\getgridprop.py" "C:\GISWORK\NEW_WORK\delete_dem"

Getting Raster Properties
Working on delete1dem
delete1dem Properties have been collected.


Executing: GetRasterProperties C:\GISWORK\NEW_WORK\delete_dem/delete1dem MEAN 0
Start Time: Wed Jul 15 17:36:19 2009
Mean = 357.948876
Executed (GetRasterProperties) successfully.
End Time: Wed Jul 15 17:36:19 2009 (Elapsed Time: 0.00 seconds)

Thanks,
JE


import arcgisscripting, sys, string, os
gp = arcgisscripting.create()
gp.overwriteoutput = 1
 
gp.workspace = sys.argv[1]
InFolder = sys.argv[1]
 
 
try:
    RasterClassList = gp.ListRasters()
    RasterClassList.Reset()
    RasterImage = RasterClassList.Next()
    gp.AddMessage("\n" + "Getting Raster Properties")
    while RasterImage:
      gp.AddMessage("Working on " + RasterImage)
      InFileName = InFolder + "/" + RasterImage
      InPropertyType = "MEAN"
      zmax = gp.GetRasterProperties (InFileName, InPropertyType)
      print zmax
      gp.AddMessage(RasterImage + " Properties have been collected.")
      gp.AddMessage("\n")
      RasterImage = RasterClassList.Next()
 
except:
    # Print error message if an error occurs 
    print gp.GetMessages()

Open in new window

0
Comment
Question by:justearth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 2000 total points
ID: 24865294
Maybe you can just send standard out to a file using " > output.txt", like this:
C:\Documents and Settings\u4cncmgj>c:\python24\python.exe "C:\Documents and Settings\u4cncmgj\Desktop\getgridprop.py" "C:\GISWORK\NEW_WORK\delete_dem" > output.txt

Open in new window

0
 

Author Comment

by:justearth
ID: 24865340
This works as in outputs the "print", but the output is a bit messy and will probably be headache like, given I have 1000's iterations and limited python knowledge I am afraid this method will create more headache for me.

Thanks,
JE
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24865397
I don't know what you mean... You wanted the output in a file, redirecting standard out works, but the output is messy? Would it be less messy if you created the output in a different way?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:justearth
ID: 24865441
I guess I was hoping  to have the output like I requested in the first post:

Name1 100
Name2 101


But the when I paste the output to anyother place it puts it out of order.  I can deal with it, I was hoping there was a slicker way.

Cheers,
JE
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24865582
Where does "Name1" and "Name2" come from, and what is "100" and "101"? The output you are getting does not look like the output you want at all... I don't understand how I can help you getting the output you want, please explain.
0
 

Author Comment

by:justearth
ID: 24865836
cxr:
It was not my intention to be so unclear.  

name1 100 was supposed to be a generic name to illustrate my point. From what I included above:

delete1dem 357.948876
 
This would be the desired output.  delete1dem comes from RasterImage and 357.948876 is the result from zmax.  Given that I am unsure on how to get the info I want from within ESRI ArcMap coding (e.g. If I print RasterImage it include other infor from within the software and will not finish the loop).  I will say your method for output will do me fine for now.]


Thanks,
JE
0
 

Author Closing Comment

by:justearth
ID: 31604037
Thanks,
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24865973
I'm not sure if this helps, but try to remove the calls to gp.AddMessage(), and print the RasterImage and zmax variables in the loop:
    RasterClassList = gp.ListRasters()
    RasterClassList.Reset()
    RasterImage = RasterClassList.Next()
    #gp.AddMessage("\n" + "Getting Raster Properties")
    while RasterImage:
      #gp.AddMessage("Working on " + RasterImage)
      InFileName = InFolder + "/" + RasterImage
      InPropertyType = "MEAN"
      zmax = gp.GetRasterProperties (InFileName, InPropertyType)
      print RasterImage, zmax
      #gp.AddMessage(RasterImage + " Properties have been collected.")
      #gp.AddMessage("\n")
      RasterImage = RasterClassList.Next()

Open in new window

0
 

Author Comment

by:justearth
ID: 24866426
Yes, this worked great.

Before I was using:

print RasterImage + zmax

and that was giving me some crazy stuff. This worked swell.

Cheers,
JE
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question