problems getting started with python

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

problems getting started with python

Brian Moore-7

Hi all-

Am using version 20 & have gotten started with python essentials.

With basic tools like this working fine.

 

begin program.

import spssaux

for var in spssaux.GetVariableNamesList():   

 print var

end program.

 

But in trying to adapt an example from programming and data management

 

The soundex and nysiis Functions

The soundex and nysiis functions implement two popular phonetic algorithms for indexing

names by their sound as pronounced in English. The purpose is to encode names having the same

pronunciation to the same string so that matching can occur despite differences in spelling.

Example

*python_extendedTransforms_soundex.sps.

DATA LIST FREE /name (A20).

BEGIN DATA

Abercromby

Abercrombie

END DATA.

BEGIN PROGRAM.

import trans, extendedTransforms

tproc = trans.Tfunction(listwiseDeletion=True)

tproc.append(extendedTransforms.soundex,'soundex','A20',['name'])

tproc.append(extendedTransforms.nysiis,'nsyiis','A20',['name'])

tproc.execute()

END PROGRAM.

 

Get this error

 

Traceback (most recent call last):

  File "", line 2, in

ImportError: No module named trans

 

I have downloaded trans and extendedtransforms (and unzipped the latter).

My first guess as the issue is file location (are these additions required to be in a certain location (nested somewhere in the SPSS C: folder?)

 

Thanks in advance,

Brian

Reply | Threaded
Open this post in threaded view
|

Re: problems getting started with python

Jon K Peck
Imported Python modules can be anywhere on the Python search path.  Those locations can vary, but they always include the site-packages directory under the Python installation and the extensions subdirectory under Statistics.  There are many ways to customize this list.

You can see the list of locations Python searches by running this code.
begin program.
import sys
print sys.path
end program.

It is easier to use the functions in extendedTransforms via the SPSSINC TRANS extension command, but the location issue would be the same.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        Brian Moore <[hidden email]>
To:        [hidden email],
Date:        05/08/2014 04:44 PM
Subject:        [SPSSX-L] problems getting started with python
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi all-
Am using version 20 & have gotten started with python essentials.
With basic tools like this working fine.
 
begin program.
import spssaux
for var in spssaux.GetVariableNamesList():    
 print var
end program.
 
But in trying to adapt an example from programming and data management
 
The soundex and nysiis Functions
The soundex and nysiis functions implement two popular phonetic algorithms for indexing
names by their sound as pronounced in English. The purpose is to encode names having the same
pronunciation to the same string so that matching can occur despite differences in spelling.
Example
*python_extendedTransforms_soundex.sps.
DATA LIST FREE /name (A20).
BEGIN DATA
Abercromby
Abercrombie
END DATA.
BEGIN PROGRAM.
import trans, extendedTransforms
tproc = trans.Tfunction(listwiseDeletion=True)
tproc.append(extendedTransforms.soundex,'soundex','A20',['name'])
tproc.append(extendedTransforms.nysiis,'nsyiis','A20',['name'])
tproc.execute()
END PROGRAM.
 
Get this error
 
Traceback (most recent call last):
  File "", line 2, in
ImportError: No module named trans
 
I have downloaded trans and extendedtransforms (and unzipped the latter).
My first guess as the issue is file location (are these additions required to be in a certain location (nested somewhere in the SPSS C: folder?)
 
Thanks in advance,
Brian