Select to view content in your preferred language

How to force Python to write a log file to specified location?

1905
2
Jump to solution
10-29-2012 10:38 AM
GregParent
Occasional Contributor
Hello Forum users,
I am running a SAS script that uses a Python script to work on an ArcGIS 10 SDE Feature Class. The Python script does everything to the Feature Class it is supposed to do but when it finishes does not leave a record of its success or failure in the SAS log tab. The SAS log only sees Python opening and then once it is finished closing. What I need to see is a log showing the success or failure of the Python portion of the code.
Is there a way of getting Python to dump a log file out to specific location while it is running in SAS?
Thanks for any input you may have.
Greg
Ps. I think it???s time to take a Python course!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Alum
I need to see is a log showing the success or failure of the Python portion of the code.
Is there a way of getting Python to dump a log file out to specific location while it is running in SAS?


If "print" and arcpy.AddMessage() output is not captured by SAS, yes, the only thing left is to write a log file somewhere.

You need a try/except to capture a message if the script fails, for example

try:     ... do your work ... except Exception, msg:     errMsg = "script failed\n" + str(msg)     # write a message to gp out     arcpy.AddError(errMsg)     # print a message to stdout     print  "** " + errMsg     # write to a log file     f.open("c:\\temp\\out.txt","w")     f.write(errMsg + "\n")     f.close()

View solution in original post

0 Kudos
2 Replies
curtvprice
MVP Alum
I need to see is a log showing the success or failure of the Python portion of the code.
Is there a way of getting Python to dump a log file out to specific location while it is running in SAS?


If "print" and arcpy.AddMessage() output is not captured by SAS, yes, the only thing left is to write a log file somewhere.

You need a try/except to capture a message if the script fails, for example

try:     ... do your work ... except Exception, msg:     errMsg = "script failed\n" + str(msg)     # write a message to gp out     arcpy.AddError(errMsg)     # print a message to stdout     print  "** " + errMsg     # write to a log file     f.open("c:\\temp\\out.txt","w")     f.write(errMsg + "\n")     f.close()
0 Kudos
FabianBlau
Deactivated User
0 Kudos