how to retrieve table from spss xml output in python -


i trying table outputs spssaux.createxmloutput. spss command validated spss.submit. below sample codes:

varlist = ["qpovty", "percap", "mdgrent", "qrich200k", "qnoauto", "qssben", "qed12les",         "qfemale", "qagedep", "qnatam", "qhisp", "qasian", "qfemlbr", "qserv", "qextrct",          "qcvlun", "qfhh", "qfam", "prenter", "qmoho", "qunocchu", "mhseval"] spsspcasyntax = ["factor //variables " + ' '.join(varlist) + " //missing listwise" +                 " //analysis " + ' '.join(varlist) +                 " //print univariate initial correlation kmo extraction rotation fscore" +                 " //criteria mineigen(1) iterate(25)" +                 " //extraction pc" +                 " //criteria iterate(25)" +                 " //rotation varimax" +                 " // save reg(all)" +                 " //method=correlation."] tag = spssaux.createxmloutput(spsspcasyntax, omsid = 'factor analysis') corm = spssaux.getvaluesfromxmlworkspace(tag, 'correlation matrix') print corm 

there error report corm = spssaux.getvaluesfromxmlworkspace(tag, 'correlation matrix') saying [errlevel 12] invalid handle object.

i tried debug , dig spssaux module cannot find way solve it. check call hierarchy , find 1 function embedded inside codes cannot viewed in dos mode (codes appears unrecognized symbols).

according code comments in spssaux.getvaluesfromxmlworkspace, seems minimum input of function tag , tablesubtype. tablesubtype here string correlation matrix found "oms table subtype" in spss's output.

can me or tell me how debug problem?

there several problems here. first, return code createxmloutput duple of (tag, errorcode). should check error code.
tag, errcode = spssaux.createxmloutput(...
tag pass getvaluesfromxmlworkspace first element. in case, error code 1001, , no output object created, attempt retrieve output causes error because xpath expression evaluator can't find object, , tag item passed in duple, anyway, rather actual tag, argument invalid.

so problem becomes why factor command fail. there 2 problems. 1 syntax invalid because // should /. factor might tolerate that, incorrect.

second, assembled command exceeds maximum line length. join varlist variables like
varlist = "\n".join("xxx", "yyy:, etc
, join whole command single string line breaks:
spsspcasyntax = "\n".join("factor variables", ...)
, pass string createxmloutput.

tip: easier assemble commands using named parameter substitution in command string rather joining pieces "+". example,
cmd = """commandname /varlist %(varlist)s
/someoption
/someother options""" % locals()
more readable , less error prone.

finally, here's tip if trying locate line of code raises error. default, statistics suppresses traceback error generate, because not meaningful users. however, if create environment variable named spss_extensions_raise value true before starting statistics, traceback displayed, allows pinpoint error location in code.

the way create environment variables os specific, on windows using control panel / system / advanced / environment variables. exact wording , path varies in different windows versions.

hth
jon peck


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -