Dear all,
I'm working on an old datafile and something weird is going on. There are variables named "V8_1" to "V8_12" (upper case V). I tried begin program. import spssaux vars = 'V8_1 to V8_12' dict = spssaux.VariableDict() print dict.expand(vars) end program. and it returns ['V8_1', u'v8_2', u'v8_3', u'v8_4', u'v8_5', u'v8_6', u'v8_7', u'v8_8', u'v8_9', u'v8_10', u'v8_11', 'V8_12'] So some variable names are in unicode and therefore lowercased(?) and others are not? This makes my loop over them crash with the error: File "C:\Python27\lib\site-packages\spssaux\spssaux.py", line 1093, in __getitem__ raise ValueError, _msg10 ValueError: Variable not in this dictionary Which probably has to do with inconsistent casing (it's looking for u'v8_2' but there's only 'V8_2'). Does anybody understand what's going on here and how to prevent this? |
This isn't really related to Unicode. The
doc for the expand method says
The expanded list is returned in the case as given in the call or the lower case names for expanded entries. I probably made a design mistake with that api, but you can get around this with one tiny change: begin program. import spssaux vars = 'V8_1 to V8_12' dict = spssaux.VariableDict(caseless=True) print dict.expand(vars) end program. The caseless option was added in August, 2009. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Ruben Geert van den Berg <[hidden email]> To: [hidden email], Date: 10/02/2013 02:20 PM Subject: [SPSSX-L] spssaux.VariableDict.expand renders casing incorrectly Sent by: "SPSSX(r) Discussion" <[hidden email]> Dear all, I'm working on an old datafile and something weird is going on. There are variables named "V8_1" to "V8_12" (upper case V). I tried begin program. import spssaux vars = 'V8_1 to V8_12' dict = spssaux.VariableDict() print dict.expand(vars) end program. and it returns ['V8_1', u'v8_2', u'v8_3', u'v8_4', u'v8_5', u'v8_6', u'v8_7', u'v8_8', u'v8_9', u'v8_10', u'v8_11', 'V8_12'] So some variable names are in unicode and therefore lowercased(?) and others are not? This makes my loop over them crash with the error: File "C:\Python27\lib\site-packages\spssaux\spssaux.py", line 1093, in __getitem__ raise ValueError, _msg10 ValueError: Variable not in this dictionary Which probably has to do with inconsistent casing (it's looking for u'v8_2' but there's only 'V8_2'). Does anybody understand what's going on here and how to prevent this? -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/spssaux-VariableDict-expand-renders-casing-incorrectly-tp5722355.html Sent from the SPSSX Discussion mailing list archive at Nabble.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 |
Thanks a lot Jon!
Seems to be a perfect solution! |
Free forum by Nabble | Edit this page |