Re: PYTHON script fails

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: PYTHON script fails

Mario Giesel
Hi, list,

back fom vacation I want to thank Garry and Albert-Jan for their comments.
Ouch, my syntax was really ugly - maybe my thoughts were distracted by vacation dreams ...
Garry found some mistakes and one more is that I forgot to insert the FLIP command before the python program ...
Albert-Jan managed to translate the procedure into a more elegant form.

Thanks for your help, guys, and good luck!
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
Mario Giesel
Munich, Germany