|
Hello fellows,
I get an error with a PYTHON syntax: =================================================================================================== DATA LIST FIXED /id 1-2 sex_kat 3 product1 TO product5 4-8 gewicht 10-13. BEGIN DATA 01166666 1,1 02166661 1,1 03166611 0,9 04166111 0,9 05161111 2,0 06161111 0,5 07116111 0,5 08111611 1,0 09116111 1,0 10116111 1,0 11216116 1,0 12266111 1,0 13211111 1,0 14211611 1,0 15211661 1,0 16211616 1,0 17261111 1,0 18261116 1,0 19261111 1,0 20211116 1,0 END DATA. FORMAT gewicht (F5.3). BEGIN PROGRAM PYTHON. import spss, spssaux command = "\n" varcount = spss.GetVariableCount() i = 1 command = "COMPUTE rang = 999.\n" command = command + "IF ($CASENUM = 1) rang = 0.\n" while i < varcount: command = command + "SORT CASES BY rang (A) var00" + str(i) + " (D) . \n" j = i +1 command = command + "IF (rang=999 AND $CASENUM = " + str(j) + ") rang = " + str(i) + ".\n" i = i + 1 print command spss.Submit(command) END PROGRAM. =================================================================================================== Here's the error message I get: ===================================================================================================Traceback (most recent call last): File "<string>", line 13, in ? TypeError: 'str' object is not callable =================================================================================================== Any ideas? =================================================================================================== Thanks, Mario __________________________________________________ Do You Yahoo!? Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz gegen Massenmails. http://mail.yahoo.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
Mario Giesel
Munich, Germany |
|
Mario
I'd fix the following things first, and then see where you are. 1. You haven't indented your while block 2. Instead of str(i), str(j) etc use string substitution, ie the %s operator to build your spss command strings. 3. The first statement after import is redundant, the variable is overwritten on line 5. Garry Gelade -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Mario Giesel Sent: 28 September 2008 17:22 To: [hidden email] Subject: PYTHON script fails Hello fellows, I get an error with a PYTHON syntax: ============================================================================ ======================= DATA LIST FIXED /id 1-2 sex_kat 3 product1 TO product5 4-8 gewicht 10-13. BEGIN DATA 01166666 1,1 02166661 1,1 03166611 0,9 04166111 0,9 05161111 2,0 06161111 0,5 07116111 0,5 08111611 1,0 09116111 1,0 10116111 1,0 11216116 1,0 12266111 1,0 13211111 1,0 14211611 1,0 15211661 1,0 16211616 1,0 17261111 1,0 18261116 1,0 19261111 1,0 20211116 1,0 END DATA. FORMAT gewicht (F5.3). BEGIN PROGRAM PYTHON. import spss, spssaux command = "\n" varcount = spss.GetVariableCount() i = 1 command = "COMPUTE rang = 999.\n" command = command + "IF ($CASENUM = 1) rang = 0.\n" while i < varcount: command = command + "SORT CASES BY rang (A) var00" + str(i) + " (D) . \n" j = i +1 command = command + "IF (rang=999 AND $CASENUM = " + str(j) + ") rang = " + str(i) + ".\n" i = i + 1 print command spss.Submit(command) END PROGRAM. ============================================================================ ======================= Here's the error message I get: ============================================================================ =======================Traceback (most recent call last): File "<string>", line 13, in ? TypeError: 'str' object is not callable ============================================================================ ======================= Any ideas? ============================================================================ ======================= Thanks, Mario __________________________________________________ Do You Yahoo!? Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz gegen Massenmails. http://mail.yahoo.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 __________ NOD32 3478 (20080928) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.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 |
|
In reply to this post by Mario Giesel
How can I retrieve the name of the active dataset from within Python
(version 2.4, SPSS15)? Thanks if you can help. Garry Gelade ===================== 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 |
|
The spssaux module has a function, GetDatasetInfo() that can return this.
getDatasetInfo(Info='Data') Return selected information on the current active dataset. Value is empty if none. Info can be Data name of the active file (empty if unnamed) Filter filter variable or empty Weight weight variable or empty SplitFile comma-separated split variable(s) or empty If there is no active file but there IS a dataset name, the dataset name is returned. Except for Data, the form of the information returned depends on the SPSS Output Labels preference setting. HTH, Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Garry Gelade Sent: Monday, September 29, 2008 4:21 AM To: [hidden email] Subject: [SPSSX-L] PYTHON - Get name of active dataset How can I retrieve the name of the active dataset from within Python (version 2.4, SPSS15)? Thanks if you can help. Garry Gelade ===================== 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 |
|
Thank you John.
Garry -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Peck, Jon Sent: 29 September 2008 14:07 To: [hidden email] Subject: Re: PYTHON - Get name of active dataset The spssaux module has a function, GetDatasetInfo() that can return this. getDatasetInfo(Info='Data') Return selected information on the current active dataset. Value is empty if none. Info can be Data name of the active file (empty if unnamed) Filter filter variable or empty Weight weight variable or empty SplitFile comma-separated split variable(s) or empty If there is no active file but there IS a dataset name, the dataset name is returned. Except for Data, the form of the information returned depends on the SPSS Output Labels preference setting. HTH, Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Garry Gelade Sent: Monday, September 29, 2008 4:21 AM To: [hidden email] Subject: [SPSSX-L] PYTHON - Get name of active dataset How can I retrieve the name of the active dataset from within Python (version 2.4, SPSS15)? Thanks if you can help. Garry Gelade ===================== 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 __________ NOD32 3479 (20080929) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.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 |
|
In reply to this post by Mario Giesel
Hi,
The code below may be a bit easier to read. I used underscores to indicate indentations. Cheers!! Albert-Jan COMPUTE rang = 999. IF ($CASENUM = 1) rang = 0. BEGIN PROGRAM PYTHON. import spss for i in range(spss.GetVariableCount()): ___j = i + 1 ___zi = str(i).zfill(3) ___spss.Submit(""" SORT CASES BY rang (A) var%(zi)s (D). IF (rang=999 AND $CASENUM = %(i)s ) rang = %(j)s. IF (rang=999 AND $CASENUM = %(j)s ) rang = %(i)s. """ %(locals)) END PROGRAM --- On Sun, 9/28/08, Mario Giesel <[hidden email]> wrote: > From: Mario Giesel <[hidden email]> > Subject: PYTHON script fails > To: [hidden email] > Date: Sunday, September 28, 2008, 6:22 PM > Hello fellows, > > I get an error with a PYTHON syntax: > =================================================================================================== > DATA LIST FIXED /id 1-2 sex_kat 3 product1 TO product5 4-8 > gewicht 10-13. > BEGIN DATA > 01166666 1,1 > 02166661 1,1 > 03166611 0,9 > 04166111 0,9 > 05161111 2,0 > 06161111 0,5 > 07116111 0,5 > 08111611 1,0 > 09116111 1,0 > 10116111 1,0 > 11216116 1,0 > 12266111 1,0 > 13211111 1,0 > 14211611 1,0 > 15211661 1,0 > 16211616 1,0 > 17261111 1,0 > 18261116 1,0 > 19261111 1,0 > 20211116 1,0 > END DATA. > FORMAT gewicht (F5.3). > > BEGIN PROGRAM PYTHON. > import spss, spssaux > command = "\n" > varcount = spss.GetVariableCount() > i = 1 > command = "COMPUTE rang = 999.\n" > command = command + "IF ($CASENUM = 1) rang = > 0.\n" > while i < varcount: > command = command + "SORT CASES BY rang (A) > var00" + str(i) + " (D) . \n" > j = i +1 > command = command + "IF (rang=999 AND $CASENUM = > " + str(j) + ") rang = " + str(i) + > ".\n" > i = i + 1 > print command > spss.Submit(command) > END PROGRAM. > > =================================================================================================== > Here's the error message I get: > ===================================================================================================Traceback > (most recent call last): > File "<string>", line 13, in ? > TypeError: 'str' object is not callable > > =================================================================================================== > Any ideas? > =================================================================================================== > > Thanks, > Mario > > __________________________________________________ > Do You Yahoo!? > Sie sind Spam leid? Yahoo! Mail verfügt über einen > herausragenden Schutz gegen Massenmails. > http://mail.yahoo.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 |
|
Albert,
Try %(locals()) instead of %(locals) Garry Gelade -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Albert-jan Roskam Sent: 30 September 2008 13:42 To: [hidden email] Subject: Re: PYTHON script fails Hi, The code below may be a bit easier to read. I used underscores to indicate indentations. Cheers!! Albert-Jan COMPUTE rang = 999. IF ($CASENUM = 1) rang = 0. BEGIN PROGRAM PYTHON. import spss for i in range(spss.GetVariableCount()): ___j = i + 1 ___zi = str(i).zfill(3) ___spss.Submit(""" SORT CASES BY rang (A) var%(zi)s (D). IF (rang=999 AND $CASENUM = %(i)s ) rang = %(j)s. IF (rang=999 AND $CASENUM = %(j)s ) rang = %(i)s. """ %(locals)) END PROGRAM --- On Sun, 9/28/08, Mario Giesel <[hidden email]> wrote: > From: Mario Giesel <[hidden email]> > Subject: PYTHON script fails > To: [hidden email] > Date: Sunday, September 28, 2008, 6:22 PM Hello fellows, > > I get an error with a PYTHON syntax: > ====================================================================== > ============================= DATA LIST FIXED /id 1-2 sex_kat 3 > product1 TO product5 4-8 gewicht 10-13. > BEGIN DATA > 01166666 1,1 > 02166661 1,1 > 03166611 0,9 > 04166111 0,9 > 05161111 2,0 > 06161111 0,5 > 07116111 0,5 > 08111611 1,0 > 09116111 1,0 > 10116111 1,0 > 11216116 1,0 > 12266111 1,0 > 13211111 1,0 > 14211611 1,0 > 15211661 1,0 > 16211616 1,0 > 17261111 1,0 > 18261116 1,0 > 19261111 1,0 > 20211116 1,0 > END DATA. > FORMAT gewicht (F5.3). > > BEGIN PROGRAM PYTHON. > import spss, spssaux > command = "\n" > varcount = spss.GetVariableCount() > i = 1 > command = "COMPUTE rang = 999.\n" > command = command + "IF ($CASENUM = 1) rang = 0.\n" > while i < varcount: > command = command + "SORT CASES BY rang (A) var00" + str(i) + " (D) . > \n" > j = i +1 > command = command + "IF (rang=999 AND $CASENUM = " + str(j) + ") rang > = " + str(i) + ".\n" > i = i + 1 > print command > spss.Submit(command) > END PROGRAM. > > ====================================================================== > ============================= > Here's the error message I get: > ====================================================================== > =============================Traceback > (most recent call last): > File "<string>", line 13, in ? > TypeError: 'str' object is not callable > > ====================================================================== > ============================= > Any ideas? > ====================================================================== > ============================= > > Thanks, > Mario > > __________________________________________________ > Do You Yahoo!? > Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden > Schutz gegen Massenmails. > http://mail.yahoo.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 __________ NOD32 3482 (20080930) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.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 |
| Free forum by Nabble | Edit this page |
