Very basic Python code not working

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Very basic Python code not working

Ruben Geert van den Berg
Dear all,
 
I was trying to run this Python code from the examples from SPSS devcentral but it somehow doesn't work and I don't see what's going wrong. Could anyone please shed any light on this? It seems the file handle is created correctly but in the spss.Submit command, it doesn't seem to expand. I tried to replace it by
 
spss.Submit("GET FILE='"+SPSSDIR+"<A href="file://\\employee">\\employee data.sav'.")
 
but without luck.
 
TIA,
 
Ruben van den Berg
Consultant Models & Methods
TNS NIPO
Email: [hidden email]
Mobiel: +31 6 24641435
Telefoon: +31 20 522 5738
Internet: www.tns-nipo.com
 
*Syntax.
 
BEGIN PROGRAM.
import spss, spssaux
import os.path, sys
spssaux.GetProcessInstallDir("SPSSDIR")
end program.
 
BEGIN PROGRAM python.
import spss
spss.Submit("GET FILE='SPSSDIR\\employee data.sav'.")
varcount=spss.GetVariableCount()
casecount = spss.GetCaseCount()
print "The number of variables is " + str(varcount) + " and the number of cases is " + str(casecount)
print help(spss.GetVariableCount)
END PROGRAM.

*Result in viewer (with [SET MPRINT=ON]).
 

BEGIN PROGRAM.

399 0 M> BEGIN PROGRAM.

import spss, spssaux

import os.path, sys

spssaux.GetProcessInstallDir("SPSSDIR")

end program.

403 0 M> FILE HANDLE SPSSDIR /NAME='C:\Program Files\SPSSInc\Statistics17'.

404 0 M> BEGIN PROGRAM '#

'.

405 0 M>

BEGIN PROGRAM python.

406 0 M> BEGIN PROGRAM python.

import spss

spss.Submit("GET FILE='SPSSDIR\\employee data.sav'.")

varcount=spss.GetVariableCount()

casecount = spss.GetCaseCount()

print "The number of variables is " + str(varcount) + " and the number of cases is " + str(casecount)

print help(spss.GetVariableCount)

END PROGRAM.

413 0 M> GET FILE='SPSSDIR\employee data.sav'.

Error # 63 in column 10. Text: SPSSDIR\employee data.sav

The file does not exist.

This command not executed.

414 0 M> BEGIN PROGRAM '#

'.

Traceback (most recent call last):

File "<string>", line 3, in <module>

File "C:\Python25\lib\site-packages\spss170\spss\spss.py", line 1265, in Submit

raise SpssError,error

spss.errMsg.SpssError: [errLevel 3] Serious error.




 


Express yourself instantly with MSN Messenger! MSN Messenger
Reply | Threaded
Open this post in threaded view
|

Re: Very basic Python code not working

Garry Gelade

Reuben,

 

SPSSDIR is just treated as a string. The following works.

 

BEGIN PROGRAM.

import spss, spssaux

import os.path, sys

mydir = spssaux.GetProcessInstallDir("SPSSDIR")

spss.Submit("GET FILE= '" + mydir + "\Samples\English\employee data.sav.'")

varcount=spss.GetVariableCount()

casecount = spss.GetCaseCount()

print "The number of variables is " + str(varcount) + " and the number of cases is " + str(casecount)

END PROGRAM.

 

Note the use of single plus double quotes to ensure the argument for GET FILE is a string.

 

Garry Gelade

Business Analytic Ltd

 

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ruben van den Berg
Sent: 18 June 2010 09:16
To: [hidden email]
Subject: Very basic Python code not working

 

Dear all,
 
I was trying to run this Python code from the examples from SPSS devcentral but it somehow doesn't work and I don't see what's going wrong. Could anyone please shed any light on this? It seems the file handle is created correctly but in the spss.Submit command, it doesn't seem to expand. I tried to replace it by
 
spss.Submit("GET FILE='"+SPSSDIR+"<a href="file:///\\employee">\\employee data.sav'.")
 
but without luck.
 
TIA,
 
Ruben van den Berg
Consultant Models & Methods
TNS NIPO
Email: [hidden email]
Mobiel: +31 6 24641435
Telefoon: +31 20 522 5738
Internet: www.tns-nipo.com
 
*Syntax.
 
BEGIN PROGRAM.
import spss, spssaux
import os.path, sys
spssaux.GetProcessInstallDir("SPSSDIR")
end program.
 
BEGIN PROGRAM python.
import spss
spss.Submit("GET FILE='SPSSDIR\\employee data.sav'.")
varcount=spss.GetVariableCount()
casecount = spss.GetCaseCount()
print "The number of variables is " + str(varcount) + " and the number of cases is " + str(casecount)
print help(spss.GetVariableCount)
END PROGRAM.

*Result in viewer (with [SET MPRINT=ON]).
 

BEGIN PROGRAM.

399 0 M> BEGIN PROGRAM.

import spss, spssaux

import os.path, sys

spssaux.GetProcessInstallDir("SPSSDIR")

end program.

403 0 M> FILE HANDLE SPSSDIR /NAME='C:\Program Files\SPSSInc\Statistics17'.

404 0 M> BEGIN PROGRAM '#

'.

405 0 M>

BEGIN PROGRAM python.

406 0 M> BEGIN PROGRAM python.

import spss

spss.Submit("GET FILE='SPSSDIR\\employee data.sav'.")

varcount=spss.GetVariableCount()

casecount = spss.GetCaseCount()

print "The number of variables is " + str(varcount) + " and the number of cases is " + str(casecount)

print help(spss.GetVariableCount)

END PROGRAM.

413 0 M> GET FILE='SPSSDIR\employee data.sav'.

Error # 63 in column 10. Text: SPSSDIR\employee data.sav

The file does not exist.

This command not executed.

414 0 M> BEGIN PROGRAM '#

'.

Traceback (most recent call last):

File "<string>", line 3, in <module>

File "C:\Python25\lib\site-packages\spss170\spss\spss.py", line 1265, in Submit

raise SpssError,error

spss.errMsg.SpssError: [errLevel 3] Serious error.




 


Express yourself instantly with MSN Messenger! MSN Messenger

Reply | Threaded
Open this post in threaded view
|

Re: Very basic Python code not working

Jon K Peck

Actually, GetProcessInstallDir does create an SPSS file handle with the name of its argument.  The problem in this case is that the specified file is not in the install directory.  It is in the samples/english (or whatever language) below the install directory.

HTH,
Jon Peck
SPSS, an IBM Company
[hidden email]
312-651-3435



From: Garry Gelade <[hidden email]>
To: [hidden email]
Date: 06/18/2010 06:21 AM
Subject: Re: [SPSSX-L] Very basic Python code not working
Sent by: "SPSSX(r) Discussion" <[hidden email]>





Reuben,
 
SPSSDIR is just treated as a string. The following works.
 
BEGIN PROGRAM.
import spss, spssaux
import os.path, sys
mydir = spssaux.GetProcessInstallDir("SPSSDIR")
spss.Submit("GET FILE= '" + mydir + "\Samples\English\employee data.sav.'")
varcount=spss.GetVariableCount()
casecount = spss.GetCaseCount()
print "The number of variables is " + str(varcount) + " and the number of cases is " + str(casecount)
END PROGRAM.
 
Note the use of single plus double quotes to ensure the argument for GET FILE is a string.
 
Garry Gelade
Business Analytic Ltd
 
 
From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Ruben van den Berg
Sent:
18 June 2010 09:16
To:
[hidden email]
Subject:
Very basic Python code not working

 
Dear all,

I was trying to run this Python code from the examples from SPSS devcentral but it somehow doesn't work and I don't see what's going wrong. Could anyone please shed any light on this? It seems the file handle is created correctly but in the spss.Submit command, it doesn't seem to expand. I tried to replace it by

spss.Submit("GET FILE='"+SPSSDIR+"
\\employee data.sav'.")

but without luck.

TIA,

Ruben van den Berg

Consultant Models & Methods

TNS NIPO

Email: [hidden email]

Mobiel: +31 6 24641435

Telefoon: +31 20 522 5738

Internet:
www.tns-nipo.com

*Syntax.

BEGIN PROGRAM.
import spss, spssaux
import os.path, sys
spssaux.GetProcessInstallDir("SPSSDIR")
end program.

BEGIN PROGRAM python.
import spss
spss.Submit("GET FILE='SPSSDIR\\employee data.sav'.")
varcount=spss.GetVariableCount()
casecount = spss.GetCaseCount()
print "The number of variables is " + str(varcount) + " and the number of cases is " + str(casecount)
print help(spss.GetVariableCount)
END PROGRAM.

*Result in viewer (with [SET MPRINT=ON]).

BEGIN PROGRAM.
399 0 M> BEGIN PROGRAM.
import spss, spssaux
import os.path, sys
spssaux.GetProcessInstallDir("SPSSDIR")
end program.
403 0 M> FILE HANDLE SPSSDIR /NAME='C:\Program Files\SPSSInc\Statistics17'.
404 0 M> BEGIN PROGRAM '#
'.
405 0 M>
BEGIN PROGRAM python.
406 0 M> BEGIN PROGRAM python.
import spss
spss.Submit("GET FILE='SPSSDIR\\employee data.sav'.")
varcount=spss.GetVariableCount()
casecount = spss.GetCaseCount()
print "The number of variables is " + str(varcount) + " and the number of cases is " + str(casecount)
print help(spss.GetVariableCount)
END PROGRAM.
413 0 M> GET FILE='SPSSDIR\employee data.sav'.
Error # 63 in column 10. Text: SPSSDIR\employee data.sav
The file does not exist.
This command not executed.
414 0 M> BEGIN PROGRAM '#
'.
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "C:\Python25\lib\site-packages\spss170\spss\spss.py", line 1265, in Submit
raise SpssError,error
spss.errMsg.SpssError: [errLevel 3] Serious error.






Express yourself instantly with MSN Messenger! MSN Messenger

Reply | Threaded
Open this post in threaded view
|

Re: Very basic Python code not working

Ruben Geert van den Berg
In reply to this post by Garry Gelade
Thanks a lot, that makes sense and it works!

Ruben van den Berg
Consultant Models & Methods
TNS NIPO
Email: [hidden email]
Mobiel: +31 6 24641435
Telefoon: +31 20 522 5738
Internet: www.tns-nipo.com



 

Date: Fri, 18 Jun 2010 13:17:02 +0100
From: [hidden email]
Subject: Re: Very basic Python code not working
To: [hidden email]

Reuben,

 

SPSSDIR is just treated as a string. The following works.

 

BEGIN PROGRAM.

import spss, spssaux

import os.path, sys

mydir = spssaux.GetProcessInstallDir("SPSSDIR")

spss.Submit("GET FILE= '" + mydir + "\Samples\English\employee data.sav.'")

varcount=spss.GetVariableCount()

casecount = spss.GetCaseCount()

print "The number of variables is " + str(varcount) + " and the number of cases is " + str(casecount)

END PROGRAM.

 

Note the use of single plus double quotes to ensure the argument for GET FILE is a string.

 

Garry Gelade

Business Analytic Ltd

 

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ruben van den Berg
Sent: 18 June 2010 09:16
To: [hidden email]
Subject: Very basic Python code not working

 

Dear all,
 
I was trying to run this Python code from the examples from SPSS devcentral but it somehow doesn't work and I don't see what's going wrong. Could anyone please shed any light on this? It seems the file handle is created correctly but in the spss.Submit command, it doesn't seem to expand. I tried to replace it by
 
spss.Submit("GET FILE='"+SPSSDIR+"\\employee data.sav'.")
 
but without luck.
 
TIA,
 
Ruben van den Berg
Consultant Models & Methods
TNS NIPO
Email: [hidden email]
Mobiel: +31 6 24641435
Telefoon: +31 20 522 5738
Internet: www.tns-nipo.com
 
*Syntax.
 
BEGIN PROGRAM.
import spss, spssaux
import os.path, sys
spssaux.GetProcessInstallDir("SPSSDIR")
end program.
 
BEGIN PROGRAM python.
import spss
spss.Submit("GET FILE='SPSSDIR\\employee data.sav'.")
varcount=spss.GetVariableCount()
casecount = spss.GetCaseCount()
print "The number of variables is " + str(varcount) + " and the number of cases is " + str(casecount)
print help(spss.GetVariableCount)
END PROGRAM.

*Result in viewer (with [SET MPRINT=ON]).
 

BEGIN PROGRAM.

399 0 M> BEGIN PROGRAM.

import spss, spssaux

import os.path, sys

spssaux.GetProcessInstallDir("SPSSDIR")

end program.

403 0 M> FILE HANDLE SPSSDIR /NAME='C:\Program Files\SPSSInc\Statistics17'.

404 0 M> BEGIN PROGRAM '#

'.

405 0 M>

BEGIN PROGRAM python.

406 0 M> BEGIN PROGRAM python.

import spss

spss.Submit("GET FILE='SPSSDIR\\employee data.sav'.")

varcount=spss.GetVariableCount()

casecount = spss.GetCaseCount()

print "The number of variables is " + str(varcount) + " and the number of cases is " + str(casecount)

print help(spss.GetVariableCount)

END PROGRAM.

413 0 M> GET FILE='SPSSDIR\employee data.sav'.

Error # 63 in column 10. Text: SPSSDIR\employee data.sav

The file does not exist.

This command not executed.

414 0 M> BEGIN PROGRAM '#

'.

Traceback (most recent call last):

File "<string>", line 3, in <module>

File "C:\Python25\lib\site-packages\spss170\spss\spss.py", line 1265, in Submit

raise SpssError,error

spss.errMsg.SpssError: [errLevel 3] Serious error.




 


Express yourself instantly with MSN Messenger! MSN Messenger



New Windows 7: Find the right PC for you. Learn more.
Reply | Threaded
Open this post in threaded view
|

Re: Very basic Python code not working

Ruben Geert van den Berg
In reply to this post by Jon K Peck
Thank you, Jon. In addition to Garry's solution, the syntax below now works as well. I was a bit worried about the file handle not expanding in the syntax printed back in the viewer, like
 
413 0 M> GET FILE='SPSSDIR\employee data.sav'.

but that has now turned out not to be the problem.
 
Have a nice weekend!

Ruben van den Berg
Consultant Models & Methods
TNS NIPO
Email: [hidden email]
Mobiel: +31 6 24641435
Telefoon: +31 20 522 5738
Internet: www.tns-nipo.com

 
BEGIN PROGRAM.
import spss, spssaux
import os.path, sys
spssaux.GetProcessInstallDir("SPSSDIR")
end program.
 
BEGIN PROGRAM python.
import spss
spss.Submit("GET FILE='SPSSDIR\samples\english\employee data.sav'.")
varcount=spss.GetVariableCount()
casecount = spss.GetCaseCount()
print "The number of variables is " + str(varcount) + " and the number of cases is " + str(casecount)
print help(spss.GetVariableCount)
END PROGRAM.
 

Date: Fri, 18 Jun 2010 06:45:00 -0600
From: [hidden email]
Subject: Re: Very basic Python code not working
To: [hidden email]


Actually, GetProcessInstallDir does create an SPSS file handle with the name of its argument.  The problem in this case is that the specified file is not in the install directory.  It is in the samples/english (or whatever language) below the install directory.

HTH,
Jon Peck
SPSS, an IBM Company
[hidden email]
312-651-3435



From: Garry Gelade <[hidden email]>
To: [hidden email]
Date: 06/18/2010 06:21 AM
Subject: Re: [SPSSX-L] Very basic Python code not working
Sent by: "SPSSX(r) Discussion" <[hidden email]>





Reuben,
 
SPSSDIR is just treated as a string. The following works.
 
BEGIN PROGRAM.
import spss, spssaux
import os.path, sys
mydir = spssaux.GetProcessInstallDir("SPSSDIR")
spss.Submit("GET FILE= '" + mydir + "\Samples\English\employee data.sav.'")
varcount=spss.GetVariableCount()
casecount = spss.GetCaseCount()
print "The number of variables is " + str(varcount) + " and the number of cases is " + str(casecount)
END PROGRAM.
 
Note the use of single plus double quotes to ensure the argument for GET FILE is a string.
 
Garry Gelade
Business Analytic Ltd
 
 
From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Ruben van den Berg
Sent:
18 June 2010 09:16
To:
[hidden email]
Subject:
Very basic Python code not working

 
Dear all,

I was trying to run this Python code from the examples from SPSS devcentral but it somehow doesn't work and I don't see what's going wrong. Could anyone please shed any light on this? It seems the file handle is created correctly but in the spss.Submit command, it doesn't seem to expand. I tried to replace it by

spss.Submit("GET FILE='"+SPSSDIR+"
\\employee data.sav'.")

but without luck.

TIA,

Ruben van den Berg

Consultant Models & Methods

TNS NIPO

Email: [hidden email]

Mobiel: +31 6 24641435

Telefoon: +31 20 522 5738

Internet:
www.tns-nipo.com

*Syntax.

BEGIN PROGRAM.
import spss, spssaux
import os.path, sys
spssaux.GetProcessInstallDir("SPSSDIR")
end program.

BEGIN PROGRAM python.
import spss
spss.Submit("GET FILE='SPSSDIR\\employee data.sav'.")
varcount=spss.GetVariableCount()
casecount = spss.GetCaseCount()
print "The number of variables is " + str(varcount) + " and the number of cases is " + str(casecount)
print help(spss.GetVariableCount)
END PROGRAM.

*Result in viewer (with [SET MPRINT=ON]).

BEGIN PROGRAM.
399 0 M> BEGIN PROGRAM.
import spss, spssaux
import os.path, sys
spssaux.GetProcessInstallDir("SPSSDIR")
end program.
403 0 M> FILE HANDLE SPSSDIR /NAME='C:\Program Files\SPSSInc\Statistics17'.
404 0 M> BEGIN PROGRAM '#
'.
405 0 M>
BEGIN PROGRAM python.
406 0 M> BEGIN PROGRAM python.
import spss
spss.Submit("GET FILE='SPSSDIR\\employee data.sav'.")
varcount=spss.GetVariableCount()
casecount = spss.GetCaseCount()
print "The number of variables is " + str(varcount) + " and the number of cases is " + str(casecount)
print help(spss.GetVariableCount)
END PROGRAM.
413 0 M> GET FILE='SPSSDIR\employee data.sav'.
Error # 63 in column 10. Text: SPSSDIR\employee data.sav
The file does not exist.
This command not executed.
414 0 M> BEGIN PROGRAM '#
'.
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "C:\Python25\lib\site-packages\spss170\spss\spss.py", line 1265, in Submit
raise SpssError,error
spss.errMsg.SpssError: [errLevel 3] Serious error.






Express yourself instantly with MSN Messenger! MSN Messenger



Express yourself instantly with MSN Messenger! MSN Messenger