SPSS Statistics

 View Only
  • 1.  SPSS/Python: spss.Submit() and multiline strings

    Posted Wed September 23, 2020 03:02 PM
    Hi everyone,

    I recently started using SPSS and its Python functionality, mostly using spss.Submit() and parsing SPSS syntax via multiline strings as inspss.Submit(""" echo 'Hello world.'. """)​

    , which works fine when calling it from the main script. However, when calling this from within a module, say:

    from pp import mm mm.myfun()

    , where mm.py looks like

    def myfun(): spss.Submit(""" echo 'Hello world.'. """)​

    I get an error message, reading that "the first word in the line is not recognized as an SPSS command" (error 1, command name is blank). Am I missing something here? I also checked whether there the source of spss.py is the same in both examples, but it is... I would appreciate your help.

    Best regards,
    Sascha


    #SPSSStatistics


  • 2.  RE: SPSS/Python: spss.Submit() and multiline strings

    IBM Champion
    Posted Wed September 23, 2020 03:35 PM
    This is tricky.  At the end of  your Submit line, you have a ZERO WIDTH SPACE character.  You can't see it, by  definition, but if you put the cursor at the end of the line and backspace, you will see that the cursor doesn't move.  The character code is 200B in Unicode or E2 80 88 in UTF-8.

    If you are passing this code in external mode from your module, Statistics is probably not running in Unicode mode, so you get different behavior with odd characters.

    Delete that character and  you will be fine.

    --





  • 3.  RE: SPSS/Python: spss.Submit() and multiline strings

    Posted Thu September 24, 2020 06:24 AM
    Thanks Jon for your reply. The suggested special character did not seem to be the problem. However, pointing me to a possible encoding issue was very helpful. In fact, replacing a leading tab with leading spaces would solve the issue.

    Best regards,
    Sascha



  • 4.  RE: SPSS/Python: spss.Submit() and multiline strings

    IBM Champion
    Posted Thu September 24, 2020 11:01 AM
    When I ran that Python code snippet, it gave me a Python syntax error on the ZWSP, but a tab in the Submit syntax could also cause a problem.  It ought to be treated as a blank, but apparently in external mode it is not.

    ------------------------------
    Jon Peck
    ------------------------------