|
Hi all,
Is there a simple way to make the VariableDict class work case-insensitively? The VariableDict class is case-sensitive whereas Spss itself is case-insensitive. Usually names of Spss variables are in lower case, so it doesn't really matter, but occasionally uppercase letters are used. For illustration, see the code below: data list free / lowercase UPPERCASE CamelCase. begin data 1 1 1 end data. begin program. import spss, spssaux print "\n--> This works:" vd = spssaux.VariableDict(['lowercase', 'UPPERCASE', 'CamelCase']) for v in vd: print v.VariableName print "\n--> This doesn't work (although I'd prefer this!):" vd = spssaux.VariableDict(['lowercase', 'uppercase', 'camelcase']) for v in vd: print v.VariableName print "\n--> This works, but seems a bit awkward:" vlist = " ".join(spssaux.GetVariableNamesList()) vlist2 = " ".join([v.lower() for v in spssaux.GetVariableNamesList()]) spss.Submit("rename vars (%s = %s)." % (vlist, vlist2)) vd = spssaux.VariableDict(['lowercase', 'uppercase', 'camelcase']) for v in vd: print v.VariableName end program. Thanks in advance! Albert-Jan ===================== 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 |
|
This case sensitivity in the spssaux VariableDict class has bothered me ever since I created it. Python is case sensitive, so it seemed reasonable, while SPSS is not, so it seemed unreasonable.
The reason for case sensitivity had to do with efficiency in lookups along with minimizing memory overhead. I now know how to make the VariableDict object case insensitive with only an unnoticeable speed cost, so I'm working on making this class case insensitive. This would be a small backwards compatibility issue, but I doubt that anyone would care. I should have an experimental version to try out in a few days. Anyone interested in testing it please email me at [hidden email], and I'll send you the revised spssaux module after it passes my preliminary testing. Regards, Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Albert-Jan Roskam Sent: Tuesday, August 18, 2009 6:20 AM To: [hidden email] Subject: [SPSSX-L] spssaux.VariableDict(['lowercase', 'UPPERCASE', 'CamelCase'] Hi all, Is there a simple way to make the VariableDict class work case-insensitively? The VariableDict class is case-sensitive whereas Spss itself is case-insensitive. Usually names of Spss variables are in lower case, so it doesn't really matter, but occasionally uppercase letters are used. For illustration, see the code below: data list free / lowercase UPPERCASE CamelCase. begin data 1 1 1 end data. begin program. import spss, spssaux print "\n--> This works:" vd = spssaux.VariableDict(['lowercase', 'UPPERCASE', 'CamelCase']) for v in vd: print v.VariableName print "\n--> This doesn't work (although I'd prefer this!):" vd = spssaux.VariableDict(['lowercase', 'uppercase', 'camelcase']) for v in vd: print v.VariableName print "\n--> This works, but seems a bit awkward:" vlist = " ".join(spssaux.GetVariableNamesList()) vlist2 = " ".join([v.lower() for v in spssaux.GetVariableNamesList()]) spss.Submit("rename vars (%s = %s)." % (vlist, vlist2)) vd = spssaux.VariableDict(['lowercase', 'uppercase', 'camelcase']) for v in vd: print v.VariableName end program. Thanks in advance! Albert-Jan ===================== 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 |
| Free forum by Nabble | Edit this page |
