|
Hi python fans, I tried an example from the "Programming with SPSS and Python" handbook but got an error message. Can you help me out?
Thanks a lot, Mario
* ==========================================================. DATA LIST FREE / id gender age incat region score1 score2 score3. BEGIN DATA 1 0 35 3 10 85 76 63 END DATA. BEGIN PROGRAM PYTHON. import spss, spssaux varDict=spssaux.VariableDict() print "\n".join(varDict.Variables(pattern=r'.*\d$')) END PROGRAM. * ==========================================================.
Traceback (most recent call last): File "<string>", line 3, in ? TypeError: 'list' object is not callable
Mario Giesel
Munich, Germany |
|
Hi Mario!
I don't know why the example doesn't work. The code below produces the same output. import spssaux varDict=spssaux.VariableDict(pattern=r'.*\d$') for v in varDict: print v.VariableName Cheers!! Albert-Jan --- On Thu, 4/2/09, Mario Giesel <[hidden email]> wrote: > From: Mario Giesel <[hidden email]> > Subject: Python TypeError > To: [hidden email] > Date: Thursday, April 2, 2009, 8:48 AM > > Hi python fans, > I tried an example from the "Programming with SPSS > and Python" handbook but got an error message. Can you > help me out? > > Thanks a lot, > Mario > > * > ==========================================================. > DATA LIST FREE > / id gender age incat region score1 score2 score3. > BEGIN DATA > 1 0 35 3 10 85 76 63 > END DATA. > BEGIN PROGRAM PYTHON. > import spss, spssaux > varDict=spssaux.VariableDict() > "\n".join(varDict.Variables(pattern=r'.*\d$')) > > END PROGRAM. > * > ==========================================================. > > Traceback (most recent call last): > File "<string>", line 3, in ? > TypeError: 'list' object is not > callable > > > > ===================== 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 |
|
In reply to this post by Mario Giesel
A VariableDict
object has a variables property that is a simple list of variable names. (This
is aliased also as Variables.) The function
that allows filtering by pattern, type etc, is variablesf So the line
causing the error below should be print "\n".join(varDict.variablesf(pattern=r'.*\d$')) That will call
the variablesf method and return the filtered list of variables to the join
function. If this example is incorrect in the current edition of the book, we
should fix that for the next edition. HTH, Jon Peck From: SPSSX(r)
Discussion [mailto:[hidden email]] On
Behalf Of Hi python fans, I tried an example from the "Programming with SPSS and
Python" handbook but got an error message. Can you help me out? Thanks a lot, Mario * ==========================================================. DATA LIST FREE / id gender age incat region score1 score2 score3. BEGIN DATA 1 0 35 3 10 85 76 63 END DATA. BEGIN PROGRAM PYTHON. import spss, spssaux varDict=spssaux.VariableDict() print "\n".join(varDict.Variables(pattern=r'.*\d$')) END PROGRAM. * ==========================================================. Traceback (most recent call last): File "<string>", line 3, in ? TypeError: 'list' object is not callable |
|
In reply to this post by Albert-Jan Roskam
Thanks to Albert-Jan and Jon - both approaches work!
* The program looks for all variables that end with a digit and prints their names into the viewer..
* ==========================================================.
* Jon Peck solution. BEGIN PROGRAM PYTHON. END PROGRAM.
* Albert-Jan solution. BEGIN PROGRAM PYTHON. import spssaux END PROGRAM.
> From: Mario Giesel <[hidden email]> > Subject: Python TypeError > To: [hidden email] > Date: Thursday, April 2, 2009, 8:48 AM > > Hi python fans, > I tried an example from the "Programming with SPSS > and Python" handbook but got an error message. Can you > help me out? > > Thanks a lot, > Mario > > * > ==========================================================. > DATA LIST FREE > / id gender age incat region score1 score2 score3. > BEGIN DATA > 1 0 35 3 10 85 76 63 > END DATA. > BEGIN PROGRAM PYTHON. > import spss, spssaux > varDict=spssaux.VariableDict() > "\n".join(varDict.Variables(pattern=r'.*\d$')) > > END PROGRAM. > * > ==========================================================. > > Traceback (most recent call last): > File "<string>", line 3, in ? > TypeError: 'list' object is not > callable > > > >
Mario Giesel
Munich, Germany |
| Free forum by Nabble | Edit this page |
