Date: Thu, 26 Aug 2010 11:47:44 +0000
Reply-To: Ruben van den Berg <ruben_van_den_berg@hotmail.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Ruben van den Berg <ruben_van_den_berg@hotmail.com>
Subject: Re: What's wrong with this Python line?
In-Reply-To: <151575.77316.qm@web110711.mail.gq1.yahoo.com>
Content-Type: multipart/alternative;
I see. The thing is that the [for f in...] part should come after all concatenations involving [f].
Well, thanks a lot for another valuable lesson!
Ruben van den Berg
Consultant Models & Methods
TNS NIPO
E ruben.van.den.berg@tns-nipo.com
P +31 6 24641435
I www.tns-nipo.com
Date: Thu, 26 Aug 2010 04:05:14 -0700
From: fomcl@yahoo.com
Subject: Re: What's wrong with this Python line?
To: SPSSX-L@LISTSERV.UGA.EDU
Hi Ruben,
This adds a period in two places; I'm not sure where you want it to be:
>>> dropvars=['bli','blo','bla']
>>> print ['hello ' + f + '.' for f in dropvars] + ['.']
['hello bli.', 'hello blo.', 'hello bla.', '.']
>>>
Cheers!!
Albert-Jan
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: Ruben van den Berg <ruben_van_den_berg@hotmail.com>
To: SPSSX-L@LISTSERV.UGA.EDU
Sent: Thu, August 26, 2010 12:37:35 PM
Subject: Re: [SPSSX-L] What's wrong with this Python line?
Hi Albert-Jan,
Thanks, but if I run
begin program.
dropvars=['bli','blo','bla']
print ['hello '+f for f in dropvars]
end program.
then I concatenate a string ('hello ') to a list as well, right?
I did notice that this
begin program.
dropvars=['bli','blo','bla']
print ['hello '+f for f in dropvars+'.']
end program.
Renders the usual error.
Lovely solution BTW! Thanks a lot!
Ruben van den Berg
Consultant Models & Methods
TNS NIPO
E ruben.van.den.berg@tns-nipo.com
P +31 6 24641435
I www.tns-nipo.com
Date: Thu, 26 Aug 2010 02:55:59 -0700
From: fomcl@yahoo.com
Subject: Re: What's wrong with this Python line?
To: SPSSX-L@LISTSERV.UGA.EDU
Hi Ruben,
You're trying to concatenate different data types, namely list and str (the dot). That won't work. How about this:
dropvars=['bli','blo','bla']
spss.Submit( "select if (" + " and ".join(["v1 ne " + d for d in dropvars]) + ")." )
so
L1 = [1]
L2 = [2]
L3 = L1 + L2
S1 = "1"
S2 = "2"
S3 = S1 + S2
But not: L1 + S1
Cheers!!
Albert-Jan
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: Ruben van den Berg <ruben_van_den_berg@hotmail.com>
To: SPSSX-L@LISTSERV.UGA.EDU
Sent: Thu, August 26, 2010 10:12:42 AM
Subject: [SPSSX-L] What's wrong with this Python line?
Dear all,
I've a list (dropvars) consisting of strings. These reside in string variable v1. I want to remove all cases for which v1 takes on a value in dropvars. The syntax I wish to generate is
sel if v1 ne "bli" and
v1 ne "blo" and
v1 ne "bla".
(dropvars=['bli','blo','bla'])
I tried
spss.Submit(['sel if ']+['v1 ne "'+k for k in dropvars[0:len(dropvars)-2]+'" and']+['v1 ne "'+dropvars[len(dropvars)-1]+'".'])
to accomplish this (I though I saw Albert-Jan submitting lists to SPSS) but I get the error
TypeError: can only concatenate list (not "str") to list
AFAIK, I'm just trying to concatenate 3 lists (the first and last consisting of a single string element). Could anybody please help? Alternative solutions are (obviously!) appreciated as well.
TIA!
Ruben van den Berg
Consultant Models & Methods
TNS NIPO
E ruben.van.den.berg@tns-nipo.com
P +31 6 24641435
I www.tns-nipo.com
[text/html]