Hi,
In help(spss.Submit) it says "cmdList: A string, list, or tuple of command lines.". Does this mean ANY string, or only bytestrings?
I have a trivial syntax with just a bunch of SHOW commands. If I open it with codecs.open, I get an error. If I simply use the builtin open() function, it works flawlessly.
begin program.
import codecs
import spss
# sample syntax.
f = r"c:\cbstemp\user\syntax.sps"
with codecs.open(f, mode="wb", encoding="cp1252") as syntax:
syntax.write("\r\n\r\nshow license.\r\nshow environment.\r\n")
with codecs.open(f, encoding="cp1252") as syntax:
spss.Submit(syntax.read())
#spss.Submit(syntax.read().replace(u"\r\n", u"\n"))
end program.
Error # 1. Command name:
The first word in the line is not recognized as an SPSS Statistics command.
Execution of this command stops.
Traceback (most recent call last):
File "", line 12, in
File "C:\Program Files\Python27\lib\site-packages\spss200\spss\spss.py", line 1522, in Submit
raise SpssError,error
spss.errMsg.SpssError: [errLevel 3] Serious error.
Perhaps this is something that was addressed already? (still v20)
regards,
Albert-Jan
Answer by JonPeck (4671) | Oct 20, 2014 at 01:30 PM
This problem actually has nothing to do with the encoding. The \r\n is the problem. Since Python uses universal line endings, the syntax string should just use \n. I think you are getting isolated \r bytes in the syntax stream.
In general, the Submit api will convert the string or Unicode string to match the Statistics mode. I think that works correctly in V20 as well as current versions, but I haven't tried that.
It will be really nice when we eventually get to Python 3 where characters are always Unicode!
Variable character limit in PSM (SPSS)? 3 Answers
Problems with FUZZY 1.4.1 with PSM 1.4.2 3 Answers
Spssdata module documentation missng in Statistics 22 0 Answers
Parsing a text string 2 Answers