[Tutor] spss.BasePivotTable

Steven D'Aprano steve at pearwood.info
Wed Aug 28 04:19:11 CEST 2013


On 27/08/13 23:14, Albert-Jan Roskam wrote:
> Hello,
>
> I am trying to create a BasePivot table with three columns: one for the labels, one for a a category "Before" and one for "After". The following attempt fails, but what am I doing wrong?

At least two things. Here is the first:

> try:
     [much code]
> except spss.SpssError:
>      print "Error."

You should replace that line with:

print """Python gives you a nice traceback showing you exactly
what went wrong and where it went wrong, but I'm not going to
show it to you. Instead, you have to guess, because Screw You.
"""

It's a little more wordy, but more accurate.



And the second:

> print spss.GetLastErrorMessage()

You're apparently not reading what the last error message is, or if you have read it, you're keeping it a secret from us.


What you actually ought to do is preferably get rid of the try...except altogether, at least while debugging. Your aim as a programmer is not to hide errors, but to eliminate them. Hiding them only makes it harder to identify the errors, which is the first step in eliminating them.

If you truly cannot get rid of the try...except, then do this instead:


try:
     [much code]
except spss.SpssError:
     print spss.GetLastErrorMessage()
     raise



which will give you both the spss last error message, and the Python traceback.




-- 
Steven


More information about the Tutor mailing list