I want to try a block of code, if it errors out, I want to save a text file of the output, and also I want for all statements in the try Not to execute (or at least stop after the error). A solution seems to be to use
insert fil..... error=stop. but this causes my spss to crash when it is used inside a try:except:. (unknown error causes processor to stop) and then i can't run anything unless i restart. I also tried this inside the try: spss.Submit(""" get file 'K:fake_file_year_2014.sav'. get file 'k:/eps_year_2013.sav'. save outfile='k:/meinzer/failstest.sav'. which is the same as whats in the insert file, but the failed 2014 year file does not stop the execution of the save on the 2013 file which does exist. here's all my code: begin program. import spss try: spss.Submit(""" *insert file='k:/meinzer/prodtest/fails.sps' error=stop. get file 'k:/eps_year_2014.sav'. get file 'k:/eps_year_2013.sav'. save outfile='k:/meinzer/failstest.sav'. """) except: spss.Submit(""" output new. """) print "failed." spss.Submit(""" OUTPUT EXPORT /text DOCUMENTFILE='k:/meinzer/FailsinFile.txt'. """) end program. Thanks again |
Don't know why this happens. But you can simply split the file on a dot and the line ends and submit all the commands?
import re, os import spss with open("d:/temp/somesyntax.sps", "rb") as f: BOM_UTF8 = "\xef\xbb\xbf" code = f.read().lstrip(BOM_UTF8) cmds = re.split("(?<=\\.)%s[\t ]*" % os.linesep, code, flags=re.M) cmds = [cmd.lstrip() for cmd in cmds if not cmd.startswith("*")] for cmd in cmds: try: spss.Submit(cmd): except Exception, e: print "uh-oh", e Regards, Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ----- Original Message ----- > From: ChetMeinzer <[hidden email]> > To: [hidden email] > Cc: > Sent: Monday, June 17, 2013 7:24 PM > Subject: [SPSSX-L] error try insert error=stop crashing spss > > I want to try a block of code, if it errors out, I want to save a text file > of the output, and also I want for all statements in the try *Not * to > execute (or at least stop after the error). A solution seems to be to use > insert fil..... error=stop. > but this causes my spss to crash when it is used inside a try:except:. > (unknown error causes processor to stop) and then i can't run anything > unless i restart. > > I also tried this inside the > try: > spss.Submit(""" > get file 'K:fake_file_year_2014.sav'. > get file 'k:/eps_year_2013.sav'. > save outfile='k:/meinzer/failstest.sav'. > which is the same as whats in the insert file, but the failed 2014 year file > does not stop the execution of the save on the 2013 file which does exist. > > here's all my code: > begin program. > import spss > try: > spss.Submit(""" > *insert file='k:/meinzer/prodtest/fails.sps' error=stop. > get file 'k:/eps_year_2014.sav'. > get file 'k:/eps_year_2013.sav'. > save outfile='k:/meinzer/failstest.sav'. > """) > except: > spss.Submit(""" > output new. > """) > print "failed." > spss.Submit(""" > OUTPUT EXPORT > /text DOCUMENTFILE='k:/meinzer/FailsinFile.txt'. > """) > > end program. > > > > Thanks again > > > > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/error-try-insert-error-stop-crashing-spss-tp5720775.html > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD > ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
So that puts every line in a try statement? wow, that's great thinking. do you use it?
Thank you for sharing! Does anyone else have any error checking code? |
Free forum by Nabble | Edit this page |