|
Dear all,
Does anyone understand the following? If I run begin program. help(cursor) end program. in SPSS syntax, I get normal results. However, if I run >>> help(cursor) in IDLE, I only get the following error: Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> help(cursor) NameError: name 'cursor' is not defined I hope this is not a dumb question, but shouldn't these render the same result? TIA! Ruben van den Berg Consultant Models & Methods TNS NIPO Email: [hidden email] Mobiel: +31 6 24641435 Telefoon: +31 20 522 5738 Internet: www.tns-nipo.com New Windows 7: Find the right PC for you. Learn more. |
|
|
Hi Albert-Jan (and others),
Thank you but I think this is even more complicated. If I run begin program. import spss,spssdata end program. begin program. help(cursor) end program. I get an error. However, by running (some Python 'borrowed' from Jon Peck) dataset close all. cd'C:\Program Files\SPSSInc\PASWStatistics18\Samples\English'. get file'1991 U.S. General Social Survey.sav'. dataset name gss. begin program. import spss,spssdata rowvar="life" colvar="happy" cursor=spssdata.Spssdata(colvar,omitmissing=True) allvalues=set([case[0] for case in cursor]) print allvalues end program. begin program. help(cursor) end program. I get help on an spssdata object. I guess it's the program block that 'activates' or invokes the help function. Best, Ruben van den Berg Consultant Models & Methods TNS NIPO Email: [hidden email] Mobiel: +31 6 24641435 Telefoon: +31 20 522 5738 Internet: www.tns-nipo.com Date: Thu, 15 Jul 2010 01:57:41 -0700 From: [hidden email] Subject: Re: Difference between Python program block and equivalent command in IDLE To: [hidden email]
New Windows 7: Simplify what you do everyday. Find the right PC for you. |
|
The argument of the help function must be qualified in the same way as any other object name in Python code. If you run (capitalizing the function name to match the module definition) begin program. help(Cursor) end program. you will get an error message, the same as from IDLE. The difference you are seeing is probably due to the fact that objects are retained between programs within your SPSS Statistics session. But running begin program. import spss help(Cursor) end program. will still give an error. What would work is begin program. import spss help(spss.Cursor) end program. After having done this once in the session, you could run the following successfully begin program. help(spss.Cursor) end program. No modules are automatically imported. If you are running in external mode - with IDLE or any other Python IDE, you will see the same behavior as long as your Python job has not terminated. There is another difference that bears on this discussion. The examples above are all about programmability. If you run a Python script, though, with the SCRIPT command, state is not maintained from one script execution to another, so the imports need to be repeated. HTH, Jon Peck SPSS, an IBM Company [hidden email] 312-651-3435
Hi Albert-Jan (and others), Thank you but I think this is even more complicated. If I run begin program. import spss,spssdata end program. begin program. help(cursor) end program. I get an error. However, by running (some Python 'borrowed' from Jon Peck) dataset close all. cd'C:\Program Files\SPSSInc\PASWStatistics18\Samples\English'. get file'1991 U.S. General Social Survey.sav'. dataset name gss. begin program. import spss,spssdata rowvar="life" colvar="happy" cursor=spssdata.Spssdata(colvar,omitmissing=True) allvalues=set([case[0] for case in cursor]) print allvalues end program. begin program. help(cursor) end program. I get help on an spssdata object. I guess it's the program block that 'activates' or invokes the help function. Best, Ruben van den Berg Consultant Models & Methods TNS NIPO Email: [hidden email] Mobiel: +31 6 24641435 Telefoon: +31 20 522 5738 Internet: www.tns-nipo.com Date: Thu, 15 Jul 2010 01:57:41 -0700 From: [hidden email] Subject: Re: Difference between Python program block and equivalent command in IDLE To: [hidden email]
New Windows 7: Simplify what you do everyday. Find the right PC for you. |
| Free forum by Nabble | Edit this page |
