I'm a beginner to Python coding and now working on a basic script program, where I'm using both Print and arcpy.AddMessage/arcpy.AddError in a standalone script for ArcMap or in Pythonwin. However, I'm having issues with how I can do this for arcpy.GetMessages in PythonWin to find a traceback error.
I tried using:
msgs = arcpy.GetMessages(2)
print (msgs)
arcpy.AddMessage(msgs)
But couldn't get any traceback message. Is there a code that helps show the traceback error in Pythonwin?
Full Script below:
Solved! Go to Solution.
As a note... if you take everything out of a try except block, you will get an error message which is largely the same as would be returned otherwise. I quite using try except blocks a long time ago... especially in cases where you only want to get the traceback messages rather than 'do' something else on failure.
From notes I made a long time agoo
Script variants | Output |
---|---|
A very simple script, with an obvious error.
| ( IDE dependent message.... ) File "Path_to_script\script_name.py", line 1, in <module> print(something) NameError: name 'something' is not defined |
As above, but getting smarter.
| >>> ooops |
Lets bring out the tools and see if that helps.
| >>> Traceback (most recent call last): File "Path_to_script\script_name.py", line 5, in <module> print(something) NameError: name 'something' is not defined None |
You can draw your own conclusions which is the most useful
As a note... if you take everything out of a try except block, you will get an error message which is largely the same as would be returned otherwise. I quite using try except blocks a long time ago... especially in cases where you only want to get the traceback messages rather than 'do' something else on failure.
From notes I made a long time agoo
Script variants | Output |
---|---|
A very simple script, with an obvious error.
| ( IDE dependent message.... ) File "Path_to_script\script_name.py", line 1, in <module> print(something) NameError: name 'something' is not defined |
As above, but getting smarter.
| >>> ooops |
Lets bring out the tools and see if that helps.
| >>> Traceback (most recent call last): File "Path_to_script\script_name.py", line 5, in <module> print(something) NameError: name 'something' is not defined None |
You can draw your own conclusions which is the most useful