Dear List, SPSS,
We are all very excited of course with the prospect of running scripts synchronously with syntax (and vice versa). For small scripts one can quickly convert them to python scripts and be done. For larger tasks one might want to call the script from syntax using python to accmplish the synchronous execution of the desired code. Does anyone know if the following would then execute as one would hope? *COMMAND submitted to SPSS. !myscript. *WHERE !myscript :=. DEFINE !myscript () INCLUDE FILE='C:\MyFolder\Myscript.sps'. !ENDDEFINE. *WHERE "C:\MyFolder\Myscript.sps" :=. ****. BEGIN PROGRAM. import spss spss.Submit(r""" SCRIPT FILE='C:\MyFolder\Myscript.sbs'. """) END PROGRAM. Thanks! Alex Rasker |
I think you misunderstand how this works. The Python program runs synchronously with syntax, but submitting a SCRIPT command will work the same way it always worked -- asynchronously.
The technique for synchronous scripting is to translate the old script into Python and then it will run synchronously. Now, since Python (with the third-party win32com module that you can find from the Python site), can use the same OLE automation methods as SaxBasic scripting, it is possible to translate your script and use the same calls. If you go the Python route, start with the viewer module, which gives you easy access to the Viewer objects and handles certain technical details for you. If, however, you are using SaxBasic to get at the SPSS data and dictionary or run syntax, this can be done much better using the new Python apis or the spssaux module from Developer Central. Now, there is one other possibility -- you have to set this up carefully. Using Python, you can run another program and wait for it to complete (look at the open functions in the os module). So you could insert some flavor of an os.popen() call into your syntax stream inside BEGIN PROGRAM. This would invoke another program - say a VB executble (SaxBasic is a flavor of VBA) running in a separate process. That program could access the Viewer contents of the first process and execute the SaxBasic code. Developer Central and the third edition of the Data Management book (downloadable as a pdf file for free) have an article on the details of translation a SaxBasic script into Python code. Remember also that autoscripts, which still must be written in SaxBasic, automatically synchronize because they are driven by the events they are intended to respond to. HTH Jon Peck -----Original Message----- From: SPSSX(r) Discussion on behalf of Alex Rasker Sent: Sun 7/16/2006 5:28 PM To: [hidden email] Subject: [SPSSX-L] The asynchronous "problem" solved with Python...? Dear List, SPSS, We are all very excited of course with the prospect of running scripts synchronously with syntax (and vice versa). For small scripts one can quickly convert them to python scripts and be done. For larger tasks one might want to call the script from syntax using python to accmplish the synchronous execution of the desired code. Does anyone know if the following would then execute as one would hope? *COMMAND submitted to SPSS. !myscript. *WHERE !myscript :=. DEFINE !myscript () INCLUDE FILE='C:\MyFolder\Myscript.sps'. !ENDDEFINE. *WHERE "C:\MyFolder\Myscript.sps" :=. ****. BEGIN PROGRAM. import spss spss.Submit(r""" SCRIPT FILE='C:\MyFolder\Myscript.sbs'. """) END PROGRAM. Thanks! Alex Rasker |
Free forum by Nabble | Edit this page |