I tried using "_" in variable names.
Received this error. Warnings cannot import name 'split' from 'string' (C:\Program Files\IBM\SPSS\Statistics\27\Python3\lib\string.py) This is a syntax snippet that demonstrates the problem. * Encoding: UTF-8. data list list /How_Store_water (a120). begin data "barrel|covered bucket without a tap" "plastic container|jug|jerry can" "does not store drinking water" "covered bucket without a tap|plastic container|jug|jerry can" "plastic container|jug|jerry can" "covered bucket without a tap" "missing unknown reason" "cistern|polytank|plastic container|jug|jerry can" "does not store drinking water" "plastic container|jug|jerry can" "plastic container|jug|jerry can" "plastic container|jug|jerry can" "plastic container|jug|jerry can" "plastic container|jug|jerry can" "plastic container|jug|jerry can" "plastic container|jug|jerry can" "plastic container|jug|jerry can" "barrel" "covered bucket without a tap" "covered bucket with tap" "covered bucket without a tap" "covered bucket without a tap" "covered bucket with tap" "missing unknown reason" "barrel|covered bucket without a tap|plastic container|jug|jerry can" "covered bucket without a tap" "covered bucket without a tap" "barrel" "covered bucket without a tap" "plastic container|jug|jerry can" "plastic container|jug|jerry can" "covered bucket without a tap" "barrel" "covered bucket with tap" "barrel" "covered bucket with tap" "covered bucket without a tap" "plastic container|jug|jerry can" "barrel|cistern|polytank|pila or tina|uncovered bucket without a tap|covered bucket without a tap|covered bucket with tap" "i purchase water as needed" "plastic container|jug|jerry can" "covered bucket without a tap" "barrel" "does not store drinking water" "covered bucket without a tap" "covered bucket with tap" "clay|ceramic jar" "plastic container|jug|jerry can" "covered bucket with tap" "uncovered bucket without a tap|plastic container|jug|jerry can" end data. FREQUENCIES variables= How_Store_Water. spssinc trans result = T_Store_Water01 to T_Store_Water12 type=25 /formula "string.split(How_Store_Water, '|')". execute. ----- Art Kendall Social Research Consultants -- Sent from: http://spssx-discussion.1045642.n5.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
Art Kendall
Social Research Consultants |
Python 3 removed the split function from the string module, along with a bunch of other functions. But you can use str.split instead. The default separator character is a blank, but you can supply a different splitting value, e.g. str.split(varname, "_") On Mon, Dec 7, 2020 at 12:15 PM Art Kendall <[hidden email]> wrote: I tried using "_" in variable names. |
in the snippet I posted I changed
spssinc trans result = T_Store_Water01 to T_Store_Water12 type=35 /formula "string.split(How_Store_Water, '|')". to spssinc trans result = T_Store_Water01 to T_Store_Water12 type=35 /formula "str.split(How_Store_Water, '|')". received this message Warnings No module named 'str' ----- Art Kendall Social Research Consultants -- Sent from: http://spssx-discussion.1045642.n5.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
Art Kendall
Social Research Consultants |
It turns out that in Python 3, str is a class not a module. Although it is automatically available, SPSSINC TRANS does not know that and thinks it is a module and tries, unsuccessfully, to import it. Hence the error. To get around this, you need to add a small wrapper function. First you define a function that wraps the split function. begin program python3. def astr(item, sep=" "): return str.split(item, sep) end program. Then use that function in the extension. spssinc trans result=x y z type=10 /formula "astr(How_Store_Water, '|')". On Mon, Dec 7, 2020 at 1:31 PM Art Kendall <[hidden email]> wrote: in the snippet I posted I changed |
The resolution to this conversation was posted as a new topic
"Untangling string multiple responses jammed into one variable" ----- Art Kendall Social Research Consultants -- Sent from: http://spssx-discussion.1045642.n5.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
Art Kendall
Social Research Consultants |
Free forum by Nabble | Edit this page |